CMSC 110 (Introduction to Computing)

Fall 2012 - Section 2

Assignment #4

Due by 4:00 pm on Tuesday, October 30, 2012

Task: Design an interactive sketch based on classes.  A new object should appear wherever the user clicks on the sketch, and each object should be animated over time.  For example, clicking could generate a snowflake that falls, or a set of concentric circles that expand outward in a rainbow and then collapse inward.  The objects can layer on top of each other in any order.

To get you started, you may use the following template for your program. You do not need to follow this template exactly, it is merely a suggestion.


from Processing import *
window(500, 500)

# Define your object here
class MyObject:

    # Constructor
    def __init__(self, x, y):
        self.x = x      # Object x-coordinate
        self.y = y      # Object y-coordinate

    # Draw the object at the current location.
    def display(self):
        # Draw the object at its current location
        pass

    # Advance the object's animation
    def step(self):
        # Change the instance variable values to advance the animation
        pass


# A list to hold all active objects
myObjects = []

# Create a new object (instance of your class)
# and append to the myObjects list
def createObject(o, e):
    pass

# Handle mousePressed events
onMousePressed += createObject

# Clear the background and redraw all objects in the myObjects list
def draw(o, e):
    background(255)
    pass

# Set up the main loop timer
frameRate(20)
onLoop += draw
loop()

Please note, at a minimum you must fill in code wherever you see a pass statement, but most likely you will need to add other variables and/or functions.  Be creative and artistic!  For example, add a background that moves behind the objects.

Hints:

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