CIT 594 Assignment 1: Recursive Drawings
Spring 2010, David Matuszek

Purpose:

General Idea:

Write six (or more) methods to make recursive drawings. The first drawing should replicate the example below.

The remaining drawings should each be distinctly different. That is, don't change just the color, or don't just replace the squares with circles--change the recursions in some way. Figure out different x, y locations for each of your drawings, or do different things at each level. At each level, you should make more than one recursive call.

In order to allow you to concentrate on the recursion, I am providing starter code that implements a simple GUI. Feel free to modify this code however you like. (I especially recommend putting more meaningful names on the buttons.)

Examples:

Draw a square (figure 1). Then at each corner of the square, draw a smaller square (figure 2). Then at the corners of each of those squares, draw even smaller squares (figure 3). Continue this process as many times as desired.

Figure 1
Figure 2
Figure 3

How to do it:

The general technique is to write a method that takes these parameters:

The initial call to this method will be with x and y representing the center of the drawing area and depth representing the maximum depth of the recursion. The method usually does something like the following:

void draw(Graphics g, int x, int y, int size, int depth) {
    if depth == 0, return
    draw some figure, centered at x, y, with the given size
    at various points around the figure {
        draw(..., a smaller size, depth-1)
    }
}

The "at various points" indicates several recursive calls, possibly in a loop, but more likely just a list of calls. Each call should be with a reduced depth, where the base case is a depth of zero (which just returns without doing anything).

This is a formula that works well, and you should probably use it to create the above drawings. But once you understand the formula, feel free to try variations on it. For example, you might omit the depth parameter, and use as a base a sufficiently small size. Also feel free to modify the GUI as needed.

To get more interesting results, here are some things you might try:

Javadoc your new methods (even if they're private). No JUnit tests in this assignment, since it's all GUI output.

Additional points:

These are not intended as additional requirements. If you get an interesting pattern (probably accidentally!) by violating some of these, feel free to keep it.

Pattern

Due Date:

Thursday, January 28, before midnight. If more than a single Java file, zip all files together. Submit via Blackboard.