CS 110 (Introduction to Computing)
Fall 2011 - Section 3
Assignment #03
Due by 4:00 pm on Friday, September 30, 2011
Task: Design an object. This can be whatever you feel like
drawing. To manage and draw your object, you should use one of
the two following approaches:
Approach 1:
- Store all properties for each object in a series of arrays, as declared below.
- Draw your objects with the function started below.
int nObjects = 10; // Set to the number of objects you would like to draw
float[] ax = new float[nObjects]; // Array of object x-locations
float[] ay = new float[nObjects]; // Array of object y-locations
float[] aw = new float[nObjects]; // Array of object widths
float[] ah = new float[nObjects]; // Array of object heights
void setup() {
// Initialize sketch and
// initialize all object property arrays here
}
void draw() {
// Draw objects here
}
void drawMyObject( float x, float y, float objectWidth, float objectHeight )
{
// Your drawing code here ...
}
Approach 2:
- Define a new object class with a draw() method, as outlined below.
- Create and store new objects in an array, and draw them with their own draw()
method.
int nObjects = 10; // Set to the number of objects you would like to draw
MyObject[] objects = new MyObject[nObjects];
void setup() {
// Initialize sketch and
// Create all objects here
}
void draw() {
// Draw objects here
}
class MyObject {
// Declare object fields (variables) here
// Constructor
MyObject(float tx, float ty, float objectWidth, float objectHeight) {
// Initialize object here
}
void draw() {
// Draw object here using its field values
}
}
Requirements:
- Insert the name of your object in place of "MyObject" in the function
or class name.
- Write a program that draws several versions (at least 3) of the object in a 500
x 500 sketch. You should use the random number function to generate x, y,
objectWidth and objectHeight values, so that the sketch changes each time it is
run. You can also vary the coloring of the object each time it is drawn. You'll
need to store colors separately.
- Your objects must interact with the mouse in two manners:
- Based on the position of the mouse. You can design
this interactivity however you like, but here are some ideas to get you started:
- Having eyes that follow the mouse position
- Flapping wings as the mouse moves
- Changing color as the mouse gets closer to the object
- Anything else you like!
- Based on when the mouse is over the object. Again, you can
design this however you like, but here are some ideas:
- Smiling if the mouse clicks on or travels over the object.
- Getting angry (e.g. changing to red, snarling, etc.) if the mouse travels over the object.
- Saying something in a text balloon when the object is clicked on.
- Anything else that interests you!
- While you may have an object that follows the mouse, you
cannot count this toward either of the two interactive components.
Pay special attention to the aesthetic aspects of your design as well as interactivity. Your sketch should be creative!!
Hints:
- Keep it simple at first. Start with something basic, get it
working, and then build upon it piece by piece, each time ensuring it
is working before you move on to the next piece.
- Start with a hand-drawing of what you want, preferrably on graph
paper.
Carefully read the Assignment Submission Policy
for how to submit your assignment.