Recursive Pictures
The recursive way to do something 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. Drawing pictures recursively is a good way to to visualize the recursive process and an elegant way to create complex and interesting pictures.
There are two different approaches to creating the artwork examples shown
below. The first is to create a recursive method that is called from the shape's
paint method. In this case, there is one shape, with one set of
instance variables, and how it is drawn is recursively. Another approach is
to actually create the complete shape from several smaller shapes, which are
themselves created from smaller shapes. In this case, there are several shapes,
with several different instance variables, and how they are created is recursive.
Then the paint method simply paints the current shape and then tells the next
shapes created to paint themselves.
Complete the following pictures using both approaches described above for each (for a total of four classes):
![]() |
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. Your solution must be recursive. |
![]() |
Smiley Face. Modify the Smiley class given as part
of this lab 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). |
![]() |
Circle Art. Make a class that represents a design of circles, with a given size, like the one shown on the left. 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). |


