Sierpinski
CSSE 221 – Fundamentals of Software Development Honors
Fall 2008–2009
Work on this exercise
individually.
Get help only from your instructor or student assistants -- that will maximize
your learning experience on this project.
Goals
The goals of this exercise are to apply and hence reinforce your understanding of:
Overview
You will write the recursive method of a project
that displays Sierpinski triangles like these:
We supply all of the project except the implementation of the recursive method
drawSierpinski -- you will write that method, per the instructions below.
Instructions
- In Eclipse, checkout the Sierpinski project
from your individual repository.
- Run the project. You should see a single triangle (the Sierpinski triangle
whose level of detail is zero).
Pressing the buttons has no effect (yet),
because you have not implemented the drawSierpinski method
(yet -- see next step of instructions).
- Read ALL of this step of the instructions before doing any of this step.
Complete the project by doing ONLY the following -- NO OTHER CHANGES ARE PERMITTED
(e.g. NO ADDITIONAL FIELDS):
- Add parameters as needed to the drawSierpinski
method in SierpinskiPanel.
- Keep the two parameters that drawSierpinski
already has -- you will need to add
more parameters for the method to become recursive.
- Change the call to drawSierpinski
at lines 69-70 of SierpinskiPanel
to have whatever additional arguments it needs.
- Keep the two existing arguments.
- Write the code for drawSierpinski --
it MUST be recursive (else no credit).
You may find the following geometric/graphical facts helpful (READ CAREFULLY):
- Draw only the BLACK triangles -- that creates the desired
effect since the supplied code supplies a blue, background triangle.
- Suppose that you have a big, right-side-up,
blue triangle (per the diagram below on the left).
Suppose that you
want to inscribe an upside-down, black triangle (to yield the diagram below on the right).
Let (X, Y) denote the coordinate of the top point of the
big, right-side-up, blue triangle.
Let L denote the length of a side of the big, right-side-up, blue triangle.
Then (in the graphics coordinates that Java and other systems use,
where the y-axis goes down, not up):
- The leftmost point of the inscribed, upside-down, black triangle is:
[X - L/4, Y + (L * sqrt(3.0) / 4.0)]
- The rightmost point of the inscribed, upside-down, black triangle is:
[X + L/4, Y + (L * sqrt(3.0) / 4.0)]
- The bottommost point of the inscribed, upside-down, black triangle is:
[X, Y + (L * sqrt(3.0) / 2.0)]
- Turn in your work by commiting your project to your individual repository.