Homework 5: Working with Functions

Due date

This homework is due on March 8, 2011 at mid-night. and must be submitted as a .pde file to the UNCA Moodle activity HW 5.

The Task

Write a function that creates an interesting shape (e.g., a groundhog, your caricature, a dog, ...) and then call that function from within draw() to make that shape appear on your canvas. Next, use either a keyboard or mouse (feel free to use both) event handler to modify that shape. For example, your program could draw a groundhog whose color changes according to the letter typed on the keyboard: if 'R' is typed its color is red; if 'B' is typed its color is brown, etc. The structure of that program would look something like this:


// declare the color variables

void setup() {
  ...
}

void draw() {
  ...
  drawHog();
  ...
}

void drawHog() {
  // contains the commands to draw a ground hog 
  // using the color variables
  ...
}

void keyPressed() {
  if (key == 'R') {
    // set the color variables to make the color red
    ..
  }
  else if (key == 'B') {
    // set the color variables to make the color brown
    ...
  }
  ...
}

For quick reference, here's a list of mouse and keyboard event handler functions:

Use a screen size of 400×400, and don't forget to document the date, your name, and the purpose of the program in comments at the start of your program.

Grading

Grades will be based on the following criteria.

25% use of a function to draw a shape
25% use of an event handler to change the shape
20% appropriate use of setup() & draw()
10% creativity and aesthetics
10% correct canvas size
10% documentation of code