25 points
For this problem, start with the code you snarfed for classwork which was called assign9_recart_cps006_spring10.
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 Target and Target2, using the two approaches above. For the rest of the pictures use either one of the approaches described above for each of the following problems. All of these solutions must be recursive. See the classwork notes on more detail for these two approaches.
![]() |
Target Complete the class, Target ,
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. Target uses approach one to paint a shape
recursively with different sizes.
Target 2 Use the second aproach for the same problem with the code Target2. Recursively create smaller shapes that are each drawn. |
![]() |
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. Complete the class, Circles , 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). |
![]() |
Competition. Complete the class, Student
that creates a piece of recursive art of your own
design. Your art work must be titled and some details
given about the algorithm used to create it (in the README
file). You should document how a user should run your program,
give expected behavior, and describe any parameters.
Your art will be entered in a Recursive Art Contest. The class will vote on the winners. See work from a previous semester here from 2008 and here from 2007 |