Step 1
I followed the guideline and drew a funny face using a circle, two lines and a triangle.
Step 2 & 3
I did them together because in this week’s class we have already been taught about the arrays to store data. I intended to randomize the speed at which the funny face moves as well as the position of it. So I first created a set of global variables shown below.
Then I created for loop function in the setup(). The idea is to create a randomly positioned face with a random speed each time it draws. The for loop will not stop until the condition is met. Therefore, it will create a set of shapes at first.
After setting up a range of random shapes, I continue in the void draw() function to make it continuous.
So I set the condition that make the shapes move continuously until it reaches the edge and set the speedX/Y [i] to negative. In this way the shapes will all move inside the screen. At the end I also write the display function to call it.
The effect is shown below:
Question 1
In setup() the function is executed once, while in draw() it executes continuously. In setup it is static while in draw it is animated.
Question 2
Array is an efficient way to store data values. It can be best applied when there are a tons of data. It can be used together with for loop to facilitate randomization. It kind of resemble variable, but allows for a wider range of values. It can be viewed as a combination of variables.