Animal Functions

Due: Must be submitted on Canvas by the end of January 28.

Goals

  • Practice writing and calling functions.
  • Practice using parameters.

Animal Functions

Step 1: Design Your Animal

On paper, sketch out at least three animal ideas -- it can be different variations of the same animal or all different animals. You can do just a head (similar to the mouse shown in lecture) or the entire animal; the choice is up to you. If you choose to do a mouse or owl, make sure it is distinct from the ones used in this class.

Then select the one that you would like to use for the assignment and draw the animal bigger on a different piece of paper and label the points that will help you in the programming.

Step 2: Create Your Animal

Program your animal in Processing, but place the drawing components into a separate function with the name of your animal. Create the setup() function as you normally would, and call your animal's function from draw().

Run your program and make sure everything looks as you want it to.

Step 3: Add Parameters to Your Animal

Add a minimum of three parameters to your animal function: representing the x-position, the y-position, and the color of some part of the animal. If you would like to use even more parameters, you are welcome to. Test out calling your animal function multiple times in draw() to create multiple copies (i.e. instances) to make sure everything is working correctly.

Step 4: Create a Row Function

Add a new function named row with a return type of void. This new function should call your animal function and produce a row of a minimum of six of your animals. Now, call row() from draw() (just once) and make sure it successfully draws a row of animals.

Step 5: Add Parameters to Your Row

Add a minimum of four parameters to your row function: representing the x position, the y position, the main color of the animal, and an odd color for the one differently colored animal. An example is shown below (you can choose the odd animal's position in the row). Run your program to make sure everything is working correctly.

Step 6: Add a Grid Function

Write a new function named grid with a return type of void that draws six rows of your animals. The "odd" colored animal should be a different color in each row. grid() should have a minimum of two parameters: representing the x position and the y position, but you can use more if it makes sense for your solution.

Step 7: Randomization [OPTIONAL]

Return to your original animal code and change either your stroke() or fill() command as shown below:

stroke(color(random(255),random(255),random(255)));
fill(color(random(255),random(255),random(255)));

It's a lot crazier! Consider why the animals no longer have their base color.

Example Solution

Animal Functions gif A working solution is shown on the right. No randomization (Step 7) is included in this solution.

This solution uses the mouse shown in lecture, which you are not allowed to use. Your oddly-colored animal should have a different color in each row. Your oddly-colored animal does not need to be the third from the left.

Submission

  • Read through the rubric carefully on the Assignment Page so you know what we will be checking for.
  • Submit your sketches from Step 1 (.jpg, .png, or .pdf) along with your finished .pde file from Step 6 (or 7).
  • When you get a chance, you should add this program to your portfolio.