CMSC110 (Introduction to Computing)
Assignment #2
Due by 2:15 pm on September 15, 2011
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 halves appropriately. The
(variable) horizontal line where the ground and sky join 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, draw clouds or something else that belongs in
the sky. If the click is on the ground,
draw rocks or something else that belongs on the ground. The size of
two objects should shrink as the mouse
position approaches the horizon line.
- Make sure that it is at least 500 pixels by 500 pixels.
- Test the mouse position 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 must shrink as they approach
the horizon to give the appearance of perspective.
- Include proper sketch source code header and adequate comments.
(See Course Coding Standards).
Use the following structure for your program.
// Header comments
// Declare variables
void setup() {
// Set up the drawing.
// Draw the sky and the ground
}
void draw() { /* remains empty */ }
void mousePressed() {
// Use the mouseY position to decide whether drawing on sky or on ground
// Compute scale factor and call appropriate drawing function.
}
// you may rename this function as necessary, depending on what you choose as your sky object
void drawCloud( int x, int y, float scal ) {
// Draw a cloud at the given coordinates using scale factor.
}
// you may rename this function as necessary, depending on what you choose as your sky object
void drawRock( int x, int y, float scal ) {
// Draw a rock 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.
- On mousePressed, different types of objects are drawn on the sky
and ground.
- As the position approaches the horizon, the objects get smaller,
giving the illusion of perspective.
- Iteration
used somewhere in the assignment.
- Variables used appropriately in the remainder of the assignment.
- Includes proper header and adequate comments.
Carefully read the Assignment
Submission
Policy for how to submit your assignment.
Optional:
If you wish, for additional creativity points, you may write functions
for drawing multiple different types of objects (i.e., more than two)
and randomly choose which objects to draw. For example, you could
draw clouds and birds in the sky, and houses and trees on the ground.