CS 110 (Introduction to Computing)
Spring 2016
Assignment #2
Due by 11:40 am on Monday, February 15, 2016
Task: Design an interactive sketch depicting the horizon. The top half of
the sketch will represent the sky and the bottom half the ground. The exact
y-coordinate of the horizon should be a variable in your code. Color the top
and bottom of your sketch appropriately. The (variable) horizontal line through the
middle of the
sketch is the horizon line at which all objects appear to vanish.
As the user clicks on the sketch draw one of two types of objects. If the click occurs
on the sky (above the horizon), draw clouds or something else that belongs in the sky. If the click is on the ground
(below the horizon), draw flowers
or something else that belongs on the ground. The size of
clouds and flowers should shrink as the mouse click position approaches the horizon
line.
- Make sure that your sketch is at least 500 pixels by 500 pixels.
- When the mouse is clicked, test the mouse position in relation to the horizon to determine which object to
draw.
- Your objects can be simple. For example, clouds could be made of multiple
ellipses, flowers could be made with nested colored ellipses and a green
rectangle, and rocks could be made of multiple rectangles.
- You must use iteration somewhere in your drawing. For example, you could use it
to draw multiple ellipses as a single cloud and multiple rectangles as a single
rock. Or, each mouse press could draw a small cluster of objects.
- Your code should use variables as appropriate.
- The size of the objects drawn must shrink as they approach the horizon to give the
appearance of perspective.
- Include proper sketch source code header and adequate comments. (See
Assignment Submission Policy).
Use the following structure for your program.
// Header comments
// Declare variables
void setup() {
// Set up the drawing.
// Draw the sky and the ground background
}
void draw() { /* remains empty */ }
void mousePressed() {
// Use the mouse position to decide whether drawing on sky or on ground
// Compute scale factor and call appropriate drawing function.
}
// You may rename this function, depending on what you choose as your sky object
void drawCloud(int x, int y, float scale) {
// Draw a cloud at the given coordinates using scale factor.
}
// You may rename this function, depending on what you choose as your ground object
void drawFlower(int x, int y, float scale) {
// Draw a flower at the given coordinates using scale factor.
}
Requirements:
- Properly drawn horizon (sky and ground).
- The y-coordinate location of the horizon should be a variable.
- The variable should be initialized once, and not change after that.
- The program should follow the rules (see below) for any value of the variable and draw correctly.
- On mousePressed, objects are drawn at mouse location. If location is in the sky, one
type of object is drawn. If location is on the ground, another type of object is drawn.
- As the position approaches the horizon, the objects get smaller, giving the
illusion of perspective.
- Iteration (for-loop or while-loop) used somewhere in the assignment.
- Variables used appropriately in the remainder of the assignment.
- Includes proper header and adequate comments.
- Design your program so that it scales properly
regardless of the size of the sketch, that is, it looks and functions the same even if I go in and change the specified size of your sketch. Hint: compute all necessary
drawing parameters based on the width and height of the sketch.
- Sign your work.
What to produce:
- The program
- A write-up with your name, course and assignment number and a paragraph about the sketch, its inspiration, and how you designed and implemented it. Include a brief discussion about your experience working on this assignment.
- A gif/jpg/png image showing off your sketch, after you have placed demonstrative sky and ground objects where you would like them (use the save() function coupled with keyPressed()).
What to Hand in:
- Submit a hard copy of 1, 2 and 3. This hard copy is due at the start of class on the due date.
- Submit an electronic copy including the entire sketch folder, the screenshot and the writeup via Dropbox shared folder as usual.
Carefully read the Assignment Submission Policy
for how to submit your assignment.