CS110 (Introduction to Computing)

Fall 2012 - Section 2

Assignment #2

Due by 4:00 pm on Tuesday, September 25, 2012

Task: Design an interactive sketch that does the following:

Somewhere within your sketch, you must use (1) variables, (2) conditional if or if-else statements, and (3) for or while loop iteration.

Other hints:

    1. Begin by randomly generating the background.  Develop this slowly, building up complexity as you go.  Test it to make sure it works after every few lines of code.
    2. Handle the onKeyPressed event with a custom function that clears the background.  Test that it works.
    3. Handle the onMousePressed or onMouseClicked event with a custom function that draws a simple shape (e.g., a single ellipse) at the mouse location upon a click.  Test that you can draw multiple objects and randomly regenerate the background.
    4. Change the simple shape to the more complex looking object you want to draw.  Test your code.
    5. Modify your complex object to adjust some aspect of its appearance (i.e. shape or size) based on the mouse location.  Test your completed program.

Use the following structure for your program.

# 1. Header comments

# 2. Load the Processing module and create a new window
# 3. Declare variables (if any)
# 4. Define your drawBackground() and drawShape() event handler functions, using the following templates

def drawBackground(o, e):
    # Draw a background that contains random elements and repetition using a for or while loop
    pass

def drawShape(o, e):
    # Draw the object at the current mouse position
    # Use mouseX(), mouseY() values to change the physical shape or color of your object
    pass

# 5. Call the drawBackground() method once to initialize the background

# 6. Handle the onKeyPressed event with the drawBackground function
#    Handle the onMousePressed or onMouseClicked event with the drawShape function

Requirements:

Carefully read the Assignment Submission Policy for how to submit your assignment.