MCS 178: Introduction to Computer Science II (Spring 2011)

Project 3: Recursive Graphics


Started: Tuesday 3/1; Due: Friday 3/4, by the beginning of class

Overview

In this project you will do several programs that draw fractal patterns.

You should work on this project individually.

Specific tasks

  1. To start out, create "Project3" folder and copy the CCurve.java file into it, and then compile and run it with several different argument values to be sure you fully understand how it works. Notice that if you interchange (x0, y0) with (x1, y1) you don't get the same image (provided level>0). That is because the c-curve depends on the direction from the first point to the second, which is to say that a c-curve has an orientation.

    Your first programming task is to write a new program in Dragon.java that does the same thing as CCurve except that for level>0, is switches the order (orientation) on the second half of the sub-curve. You should get something radically different from the c-curve; be sure you check with the lab instructor that you did the right thing.

  2. Next, create a new class called Sierpinski that will eventually be used to draw a Sierpinski gasket, as described in class. First, however, you will want to write a public static method called triangle that takes six double arguments x0 y0 x1 y1 x2 y2 and draws the triangle between the points (x0, y0), (x1, y1), and (x2, y2). Do this, testing the procedure fully. Be sure to try triangles that aren't equilateral.

  3. Now write a public static method called sierpinski which takes six double arguments x0 y0 x1 y1 x2 y2 and an int argument level and draws the Sierpinski of the given level through the given points. Again, test the procedure fully, being sure to test with points that do not form an equilateral triangle. You should see the following images with the given arguments:

    Sierpinski 0 0 1 0 .5 .866 0    Sierpinski 0 0 1 0 .5 .866 1    Sierpinski 0 0 1 0 .5 .866 2
    Level 0 Sierpinski gasket    Level 1 Sierpinski gasket    Level 2 Sierpinski gasket
                  
    Sierpinski 0 0 1 0 .5 .866 3    Sierpinski 0 0 1 0 .5 .866 4    Sierpinski 0 0 1 0 .5 .866 5
    Level 3 Sierpinski gasket    Level 4 Sierpinski gasket    Level 0 Sierpinski gasket
  4. Finally, come up with your own fractal pattern. I will discuss some possible ideas in class. Otherwise, you could play around with the program IFS.java to see some other self-similar fractals. For your convenience, following are the input files that they refer to at the top of the files:

What you must hand in

The whole project, of course which should include the two classes Dragon.java and Sierpinski.java, as well as the class that implements the fractal you create in part 4 above. You must also fill out the following readme.txt file.

Gradesheet

We will use this gradesheet when grading your lab.

Submission

Use the procedure described in our instructions on submitting code document.