Skip to main content
Engineering LibreTexts

7.5: Exercises

  • 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.

    Exercise \(\PageIndex{1}\)

    Draw the flag of Japan: a red circle on a white background that is wider than it is tall.

    Exercise \(\PageIndex{2}\)

    Modify 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.

    A recursive shape we call “Mickey Moose”.
    Figure \(\PageIndex{1}\): A recursive shape we call “Mickey Moose”.

    Exercise \(\PageIndex{3}\)

    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

    1. In the directory app02 in the repository for this book, you’ll find a file named Open it and read the paint method. Draw a sketch of what you expect it to do. Now run it. Did you get what you expected?
    2. Modify the program so that the space between the circles is larger or smaller. See what happens to the image.
    3. 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.
    4. Write a method named radial that 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.
    5. Just about any kind of graphical pattern can generate Moiré-like interference patterns. Play around and see what you can create.
    Graphical patterns that can exhibit Moiré interference.
    Figure \(\PageIndex{2}\): Graphical patterns that can exhibit Moiré interference.