Course Links

Exercises

Resources

External

A Fractal Dragon

For this lab, you will write a program that draws a shape called a fractal dragon. This is a linear fractal that connects two points. A particular dragon can be identified by a number corresponding to its complexity, called its rank or order. The order 0 and order 1 dragons are shown below.

 

For order k > 1, the dragon is defined recursively. Consider the diagram below:

The order k dragon consists of an order k-2 dragon between points A and B, an order k-1 dragon between points B and C, and another order k-2 dragon between points C and D.

Given points A and D, points B and C may be found easily. Consider the vector AD = (dx,dy). The perpendicular vector is (-dy,dx). Point B is thus A+(dx/4-dy/4,dx/4+dy/4). A similar expression holds for point C.

Coding the Dragon

A fractal dragon of order k can easily be displayed using a recursive program. Starting with this initial file, your job is to make it happen. (Note: this code combines the JDragon component with some static code that opens a GUI window to display into; this is not the best style under normal circumstances but it is convenient for labs because everything is in one file.)

When you have your program running, it is interesting to try to predict what will happen if you (temporarily) comment out one or more of the three recursive calls. Make a prediction in your head and test it out. This is a good trial of whether you truly understand recursion.

Additional Exercises

To help prepare you for the homework assignment on mazes, you should review and complete the tutorials on enumerated types, and if you have time, try the one on reading from files.

To Submit