- Page ID
The code for this chapter is in the
ap02 directory of
ThinkJavaCode. See [Section 0.4] for instructions on how to download the repository. Before you start the exercises, we recommend that you compile and run the examples.
Draw the flag of Japan: a red circle on a white background that is wider than it is tall.
Modify Mickey.java to draw ears on the ears, and ears on those ears, and more ears all the way down until the smallest ears are only 3 pixels wide.
The result should look like “Mickey Moose”, shown in Figure 16.5.1. Hint: You should only have to add or modify a few lines of code.
In this exercise, you will draw “Moiré patterns” that seem to shift around as you move. For an explanation of what is going on, see https://en.Wikipedia.org/wiki/Moire_pattern.
- In the directory
app02in the repository for this book, you’ll find a file named
Moire.java. Open it and read the
paintmethod. Draw a sketch of what you expect it to do. Now run it. Did you get what you expected?
- Modify the program so that the space between the circles is larger or smaller. See what happens to the image.
- Modify the program so that the circles are drawn in the center of the screen and concentric, as in Figure 16.5.2 (left). The distance between the circles should be small enough that the Moiré interference is apparent.
- Write a method named
radialthat draws a radial set of line segments as shown in Figure 16.5.2 (right), but they should be close enough together to create a Moiré pattern.
- Just about any kind of graphical pattern can generate Moiré-like interference patterns. Play around and see what you can create.