Based on an idea by Steve Cooper. Written by Chris Piech.
Sometimes repeating patterns can cause our eyes to see things that aren't there. Look at the picture below. Can you see little grey squares in the intersections of the white lines? Write a
GraphicsProgram that creates the optical illusion:
You may notice that the starter code for this project has the lines:
private static final int SIZE = 100;
private static final int GAP = 10;
runmethod (much like the random number generator). These lines define constants: variables whose values never change, and since they are defined outside a method you can read their value from any point in the program. Though you could write this optical illusion using the numbers 100 and 10 directly in your code, using constants makes your program much easier to read.
This problem requires using a for loop inside a for loop. Remember to use a different iterator variable for the inner loop. For example if your outer loop is of the form
for(int i = 0; i < 100; i++)
If you have time, try creating this optical illusion! Note that all the squares are the same size and all lines are horizontal! Think about how to decompose your solution.
If you are stuck, try drawing each row with the first black square always starting at x = 0. Then try to figure out how to create the offset pattern.