PS2
Home Assignments Lecture Blog Resources Discussion Group
Recursive Graphics
We'll be implementing the Sierpinski triangle assignment described at http://www.cs.princeton.edu/courses/archive/fall13/cos126/assignments/sierpinski.html.
Some notes:
- Create your own drawable entity using SFML's ConvexShape class.
- Use Jon's LineSegment example to see how to create proper class structure within/using SFML: Attach:LineDemo.tar.gz.
- In your main program, you should be able to instantiate your own Sierpinksi triangle, constructing it with a specific recursion depth, and then just have it draw itself to your main window.
// instantiate Sierpinski st(7); // parameter is recursion depth // maybe want to give it a size parameter too ... // later, in the main draw loop window.draw(st);
- Follow the process advice from the Princeton assignment: “First, make sure that your program draws a single filled equilateral triangle when N equals 1. Then, check that it draws four filled equilateral triangles when N equals 2. Your program will be nearly (or completely) debugged when you get to this point.”
- Handle the scaling however you like, but your triangle should fill the window you create for it.
- Do you need to draw the center black triangle, or should you start with a black window and then not draw to keep it black? It's not obvious... this is part of understanding the recursion... think about it.
- Turns out the answer to the question above is fairly simple. Start with a white background. Draw the upright, larger triangle with a black outline only. Then draw the center, pointing down triangle in solid black. Then recurse into each of the three smaller upright triangles.
What to turn in
It's important that you turn in everything needed to build your project.
Please note that you will have two projects for this assignment: (1) the Sierpinski implementation and (2) your own original work.
For each, please submit:
- A directory structure that contains everything needed to build—
.cpp
files.hpp
headers- a
Makefile
if you have one (or instructions if you do not) - any images you are displaying
- anything else needed to build
- Make sure to use local paths in your source code to any files that you are loading. Do not use absolute paths!
- A screenshot of your Sierpinski triangle or original recursive image
- A
readme.txt
file that includes:- Your name
- A discussion of what you did—at least 100 words. What you actually implemented, and, what was interesting, hard, fun, or easy about your project.
- How much time you invested (optional).
- Anything else you'd like us to know (optional).
- Preserve the directory structure you have on your own machine. Yes, you can use tar or zip!
Please note that all of the above is per each of the two projects!
How to turn it in
So you are going to have two gzip tar files (or regular zip archives). Please name them including your CS account username.
E.g. I might have fredm-sierpinksi.tgz
and fredm-awesome-recursion.tgz
.
Then submit with:
submit fredm 204-ps2 archive-1-file archive-2-file
But wait, there's more...
Also, I want you to share your original image with the class.
You are going to do this by uploading it to course wiki, at this page: PS2 Images.
To do this:
- name the screen shot with a filename that starts with your CS username. This is to prevent two people from picking the same name for their image and then having the second one overwrite the first. E.g. I am going to upload
fredm-htree-from-duke.jpg
(an image I found on the web) - Go to the PS2 Images page, and click (in the upper right) “Edit.” Enter the password posted to the Google discussion group.
- Add the following to the bottom of the wiki markup, replacing my name and info with your own:
Attach:fredm-htree-from-duke.jpg \\
Fred Martin \\
This is from www.cs.duke.edu-courses-fall01-cps100-assign-recursivegraph-htree4.jpg
- Click save.
- Then, the line with “Attach” will become a link with a little blue triangle.
- You're done. There will be a link to view the PS2 Images page. Click on that and you should see your image.