Project 4: Recursive Graphics
Start: Thursday 10/23; Due: Monday 11/3, by the beginning of class
Overview
In this project you will write several programs that draw fractal patterns using the collage method described in class, in which a fractal is generated by pasting together similar sub-fractals.
You should work on this project individually.
Specific tasks
-
To start out, create the
Project4
project and copy theCCurve.java
file I showed in class into the project, and then run it with several values to be sure you fully understand how it works. (You will need to get thestdlib
library into theProject4
and configure the build path appropriately.) Notice that if you interchange(x0, y0)
with(x1, y1)
you don't get the same image (unlesslevel
is 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 inDragon.java
that does the same thing asCCurve
except that whenlevel
>0, it switches the order (orientation) of the second 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. -
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 calledtriangle
that takes sixdouble
arguments (x0
,y0
,x1
,y1
,x2
, andy2
) and fills in 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. -
Now write a public static method called
sierpinski
which takes the same sixdouble
arguments and anint
argumentlevel
and draws the Sierpinski gasket 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: -
Finally, come up with your own fractal pattern using the collage method. I will discuss some possible ideas in class. Alternatively, you could play around with the program
IFS.java
to see some other self-similar fractals. Karl Knight altered this file slightly so that it will set the number of iterations inmain()
and will take input from data files in theresources
directory. For your convenience, following are the input files that they refer to at the top of the Java file:
What you must hand in
Submit the whole project, 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 same procedure to submit your code as in the previous project. Submit the zip file via Moodle. This is described in our step by step instruction on submitting code. Be sure to select f-mcs-178-003, which is the lab section.