Duke CS Logo CompSci 6: Program Design & Analysis I
(Fall 2009)
Home
Course Information
Calendar
Assignments
Assign 1
Assign 2
Assign 3
Assign 4
Assign 5
Assign 6
Assign 7
Assign 8
Assign 9
APT problems
Resources
Help sessions
Discussion Forum
Blackboard
Oasis

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 one of the approaches described above for each of the following problems.

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

Submitting

Submit all source code files and a README.txt describing your piece of recursive art.
Last updated Thu Nov 19 14:04:31 EST 2009