A fractal is a geometric figure that exhibits recursive structure. A fractal can be divided into parts where each part is a smaller version of the whole. Coastlines and edges of clouds are patterns that occur in nature that show self similarity in structure at smaller and smaller levels. To mimic a fractal pattern we can use recursive programming.
Sierpinski Gasket is built out of nested triangles. To draw this figure the following algorithm is used:
Base case: draw a triangle Recursive case: if more divisions are desired, draw three smaller gaskets within the triangle
Nested Squares is a simpler pattern that follows this algorithm:
Base case: draw a square Recursive case: if more divisions are desired, draw a smaller version of the pattern within the square
To control the recursion we need a recursion parameter. We define a level of nesting for the fractal structure that serves as our recursion parameter. For nested squares, the level-zero structure would be just the basic square shape. A level-one pattern would be the basic square shape plus an inner square and so on. The higher the level, the more subdividing we have to do.
I have provided for you a template that shows you how to implement the Sierpinski Gasket and the Nested Squares. For the assignment you will have to fill in the code that will draw the following fractal structures:
Feel free to experiment with color by using different colors for different levels. If you enjoy doing this exercise you can create your own fractal pattern and add to the list.
The file that you will be turning in will be called Fractals.java. The file will have a header of the following form:
/* File: Fractals.java Description: Student Name: Student UT EID: Course Name / Unique Number: CS 313E / 52726 Date Created: Date Last Modified: */
You will follow the standard Java Coding Conventions. You can either view the HTML page or download the PDF or Postscript and print it out. There is a modification that I would like to make to the standard coding conventions. Please align the opening and closing braces vertically so that you can easily make out the blocks of code.
Use the turnin program to submit your Fractals.java file. The TAs should receive your work by 5 PM on Sunday, 27 March 2005.