Self-Similar Shapes       CPS 004.1, 14 July 2003

Another way to do something many times is to think about the problem as made up of smaller, similar, problems. Then your task is to determine what extra work would need to be done if the smaller version of the problem has already been completed. Additionally, you need to figure when the smaller problem has a trivial implementation (i.e., drawing one square or doing nothing) - this case halts the recursion.

This exercise is meant to familiarize you with the following concepts discussed in class and your reading:

Specifications

Complete the following exercises:
Target. Make a class that represents a target with a given number of circles, each one smaller than the previous one. For example, if the target had three circles, the first should be the full size, the next two-thirds that size, and the last one, one-third that size. Similarly, if the target has five circles, the first should be full size, the next four-fifths that size, the next three-fifths, then two-fifths, and finally one-fifth the size. You should also create an Applet class within which you create an instance of your Target class. Your solution must be recursive; here is some sample psuedocode to get you started.
Circle Art. Make a class that represents a design of circles, with a given size, like the one shown below for a size of 360. Each circle design made should include four circles of one-third the original size. Finally, when it is too small to repeat the process, you should simply draw a green rectangle where you would have drawn another circle shape (for example when the size of the circle is less than ten pixels).
Sierpinski Triangle. This design is called Sierpinski's Triangle, after the Polish mathematician Waclaw Sierpinski who described some of its interesting properties in 1916. Among these is its fractal or self-similar character. The large triangle consists of three smaller triangles, each of which itself consists of three smaller triangles, each of which consists of three smaller triangles. At each level, the triangles to be created are half the size of the previous level. Note, this is different from the problem above in which a circle is created at each level because only the smallest triangles are drawn in this model.
Extra credit. Modify your smiley face such that a smaller copy of it appears within each of its eyes, and a smaller copy appears within each of those copies' eyes, and on and on until it becomes too small to effectively see the copies (i.e., about twenty pixels in size). At this point, you should simply make a standard smiley face (i.e., with nothing in its eyes).

What to Submit

You should start a new project for each shape in this exercise. You should feel free to copy your code from previous exercises, but you will be making many changes.

When you are finished, you and your partner should transfer the entire project folder created by Visual J++ to your respective public_html/cps4 folder in the acpub system and update your course web page to link to the newly transferred project using the guidelines given here.