CS 106 Winter 2018
Assignment 05: Geometric context
Question 1 Kaleidoscope
In the provided starter code, open the sketch KaleidoDraw. You will see a very simple, self-contained drawing tool. Every mouse drag draws a line in the sketch window. Pressing the space bar clears the drawing, and pressing the 's' key saves it.
Modify the sketch so that it lets you draw with the six-fold rotational and reflection symmetries of a snowflake. That is, the drawing should look the same if you rotate it around the centre of the sketch window by 60 degrees, and one side should be a mirror image of the other side. The video above shows what the sketch should look like when you're done.
To make this work, you must change the contents of the mouseDragged() function. Instead of drawing a single line, as is done now, draw twelve lines: the same line rotated six times around the centre of the sketch window, and the reflections of all those lines. Use geometric contexts as needed to obtain these twelve copies. It's possible, but not required, to do this in such a way that every call to line() is identical to the one that comes in the initial sketch.
Save your sketch as KaleidoDraw in your A05 folder.
Question 2 Hierarchical drawing
Write a Processing sketch that draws a scene of your invention, making use of geometric context functions. The scene can consist of anything you want, as long as it satisfies the conditions below.
Your sketch window should have size at least 400×400, and no more than 1000×1000. Choose a size that's most appropriate for your scene.
The scene should be figurative: it should contain clear objects (people, animals, plants, buildings, vehicles, etc.), and not consist entirely of abstract shapes.
Don't use any data from external files (images, SVG files, text files, etc.). All drawing should be based on calls to built-in drawing functions in the sketch itself.
At least one object must be an "advanced shape" (i.e., it must be drawn using beginShape(), vertex(), and endShape()).
There must be at least one object that's repeated: it should appear at least three times with different transformations, carried out using geometric context. Put the code to draw the object into a helper function, and call that function three times wrapped inside different transformations. At least one of the copies should be scaled, and at least one should be rotated.
Note that "repetition" doesn't necessarily imply the use of a loop. Suppose you have a helper function called myShape(). Then both of the following would be considered to contain three calls to the function:
pushMatrix(); // Perform some transformations myShape(); popMatrix(); pushMatrix(); // Perform some transformations myShape(); popMatrix(); pushMatrix(); // Perform some transformations myShape(); popMatrix();
for ( int idx = 0; idx < 3; ++idx ) { pushMatrix(); // Perform some transformations myShape(); popMatrix(); }
At least one object must use more than one level of hierarchy: a geometric context nested inside of another geometric context. You need to have at least one place where a call to pushMatrix() occurs while another context has already been pushed. See, for example, the door() and house() functions in the HierarchicalStreet sample sketch to see places where nested contexts are used.
The goal of this question is for you to exercise your use of translate(), rotate(), scale(), pushMatrix() and popMatrix(), but in an open-ended way. You should think carefully about what sort of scene you'd like to draw within the constraints above. We encourage you to design a visually rich and interesting scene. Needless to say, we'll award bonus marks for especially creative or artistic results.
Save your work in a sketch called HierarchicalScene, inside your A05 folder.
Submission
When you are ready to submit, please follow these steps.
Please ensure that any sketches you submit compile and run. It's better to submit a sketch that runs smoothly but implements fewer required features than one that has broken code for all features. If you get partway into a feature but can't make it work, comment it out so that the sketch works correctly without it.
If necessary, review the Code Style Guide and use Processing's built-in auto format tool. You do not need to use the precise coding style outlined in the guide, but whatever style you use, your code must be clear, concise, consistent, and commented.
If necessary, review the How To Submit document for a reminder on how to submit to LEARN.
Make sure to include a comment at the top of all source files containing your name and student ID number.
Create a zip file called A05.zip containing the entire A05 folder with its subfolders KaleidoDraw and HierarchicalScene.
Upload A05.zip to LEARN. Remember that you can (and should!) submit as many times as you like. That way, if there's a catastrophe, you and the course staff will still have access to a recent version of your code.
If LEARN isn't working, and only if LEARN isn't working, please email your ZIP file to the course account (see the course home page for the address). In this case, you must mail your ZIP file before the deadline. Please use this only for emergencies, not "just in case". Submissions received after the deadline may receive feedback, but their marks will not count.