CS 110 (Introduction to Computing)

Fall 2011 - Section 3

Assignment #2

Due by 4:00 pm on Friday, September 16, 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 through the center 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 rocks or something else that belongs on the ground. The size of clouds and rocks should shrink as the mouse position approaches the horizon line. 

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, 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, 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:

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.

Back to CS 110 (Section 3) Course Web Page