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.
To start out, create the Project4
project and copy the CCurve.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 the stdlib
library into the Project4
and configure the build path appropriately.) Notice that if you interchange (x0, y0)
with (x1, y1)
you don't get the same image (unless level
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 in Dragon.java
that does the same thing as CCurve
except that when level
>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 called triangle
that takes six double
arguments (x0
, y0
, x1
, y1
, x2
, and y2
) 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 six double
arguments and an int
argument level
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 in main()
and will take input from data files in the resources
directory. For your convenience, following are the input files that they refer to at the top of the Java file:
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.
We will use this gradesheet when grading your lab.
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 2016 s-mcs-178-001, which is your lecture section.