COS 126

Recursive Graphics
Programming Assignment

Due: 11:59pm

Write a program that can create an H-tree pattern, as illustrated below. Then develop a program that prints recursive patterns of your own design. The H-tree is another example of a fractal pattern like the Mandelbrot set. It also of practical interest in circuit design. For example, imagine that we want to lay out circuit components on a microprocessor chip so that the length of wire connecting each component to the clock is the same. This property is desirable to achieve uniform wiring delays. The H-tree pattern is an elegant solution: position the clock in the center of the biggest H, and put each circuit component at one of the exposed endpoints of the smallest H's.

Part 1.   Though the H-tree pattern looks complex, it can be generated with a recursive program very similar (in fact, identical!) to the one that draws the pattern in Figure 5.12 in Algorithms in Java. Your task is to write a program HTree.java with a recursive function and a main() driver that calls the recursive function once, and animates the results in Turtle graphics. Think recursively: write a program that draws an H and calls itself 4 times (and includes a termination condition).

Your program will read in a command line parameter N to control the depth of the recursion. First, make sure that your program can draw a single H, with N set to 1. Then, check that it draws five H's with N set to 2. Your program will be nearly (or completely) debugged when you get to this point. Below are the target H-tree patterns with N set to 1, 2, 3, 4, 5 and 6.

 

Part 2.   In this part you will create your own recursive design. First, do something different for your basic graphic design. For example, you can have the regions represented by the recursive calls be rectangles of varying size, or you can have them overlap. Or, work with X's or S's instead of H's. Or, use Turtle.spot to produce filled circles, filled squares, images, or text. Or, use five recursive calls and pentagons, or whatever. Try using color or introducing some randomness. Originality and creativity in the design will be a factor in your grade.

Submission.   Submit the files: HTree.java, Art.java, and readme.txt file. Your program Art.java should take a single command line parameter N that controls the depth of recursion. We will choose N between 1 and 7 to test it.

Extra Credit A.   Write a program to make the recursive H pattern using a non-recursive and bottom-up method like Sedgewick Program 5.9.

Extra Credit B.   Create an image to display on the Display Wall in the Frist Student Center. This requires no programming and can be alot of fun! Follow these display wall instructions to show off your artwork. Name your resulting JPEG file login.jpg where login is replaced by your email name.

Copyright © 2000 Robert Sedgewick