WEEK: 10
Active: March 14th - March 20th
Work Due: March 21st @ 9:00AM

Homework

For your homework this week you can either;

  1. Refactor an existing homework project; adapting it to use functions and an array.
  2. Create a new creative sketch, that utilizes functions and arrays.

My example below demonstrates the work we did this week in class, by creating a complex, generative smiley face example.

Specification

  1. You must create and use at least one array.
  2. You must write and use at least two functions, (not counting setup() or draw()).
  3. This should be “interesting” to look at.

As always, you should comment your code, write a readme, and provide links on the HW forum to both your git repo, and live sketch.

Instructor Example

For this week’s example, I do a number of things. However, the main goal was to create a sketch with smiley faces that rotate on the x and y axis according to a sinusoidal function. This sine function determines not only relative position, but also the scale factor of the smiley face.

As you can see from the code;

  • I created an array (smileys), to store objects holding data about each smiley.
  • I also created a variable t to track the progression of time.
  • In the setup function, I push 20 objects, representing various aspects of data necessary to draw each smiley.
  • Below the draw loop, I write 3 functions.
  • The first of these, drawSmiley() accepts a smiley object as its input. It then calls the sine function to determine position on both the x and y axis, and also calls the function to actually draw each smiley (smileyFace()).
  • The smileyFace() function is the same one you saw earlier this week.
  • The sinePos() function determines a position value based on the movement of time (time) and the timeScale of each individual smiley object.
  • Finally, in the draw() function, the array of smileys is worked through and used to draw smiley faces in orbit.
  • However, I also included a map function that maps the mouseX position between 0 and the length of the smiley array. Thereby, allowing the user to determine how many orbiting smileys that see.
[ Code Download ] [ View on GitHub ] [ Live Example ]

Previous section:
Next section: