next up previous
Next: What to turn in Up: Assignment 6: Iteration Previous: Recursion and iteration

Moiré patterns

1.
Create a new project named Moire based on the Graphics stationery. When you change the name of the class, don't forget to change it in main, too.

2.
Add the following code to your project, and replace the contents of paintBox with a single line that invokes moire.

  public static void moire
         (Graphics g, int x, int y, int width, int height) {
    int i = 1;
    while (i<width) {
      g.drawOval (0, 0, i, i);
      i = i + 2;
    }
  }

3.
Look at the code before you run it and draw a sketch of what you expect it to do. Now run it. Did you get what you expected? For a partial explanation of what is going on, see the following:

	http://math.hws.edu/xJava/other/Moire1.html
	http://tqd.advanced.org/3543/moirelesson.html
4.
Modify the program so that the space between the circles is larger or smaller. See what happens to the image.

5.
Modify the program so that the circles are drawn in the center of the screen and concentric, as in the following figure. Try using different colors.

figure=moire.eps,height=1.5in

6.
Write a method named radial that draws a radial set of line segments as shown in the figure, but draw them close enough together to create a Moire pattern.

7.
Just about any kind of graphical pattern can generate Moire-like interference patterns. Play around and see what you can create.


next up previous
Next: What to turn in Up: Assignment 6: Iteration Previous: Recursion and iteration
Allen B. Downey
1999-03-08