Recitation 7: Functions and Arrays——Cindy Xie

  • Overview: This week we learned how to make our functions in processing and also learned the function arrays.
  • Step 1:

The first step was to build three different faces. I imitated the code of the class and drew two blue and yellow faces, then I used the triangle function to draw a triangle purple face. In this step, I invented three functions of my own to draw three different faces. Then I put those three functions into my draw function.

link

  • Step 2+ Question 1:

for loop:

I used for loop for two circle faces(  because the triangle face will distort if I use for loop on it). By using for loop and function random, those faces appeared in the canvas randomly.

link

draw loop:

By using the draw loop, those faces can repeatedly keep appearing on the canvas. Compared with for loop, the draw loop can repeat the “for” action and those faces will look like keep moving on the canvas. But if we use the for loop, the faces on the canvas is unmovable because once there are 200 faces on the canvas, the action will stop. This is the difference between the draw loop and the for loop.

link

step3:

Then I used the function array to change the X, Y positions of those faces as well as their color. I used 5 arrays, two of them to control the positions and three of them to control the colors.

link

  • Step 4+Question2:

In the last step, by using the function random and function if, those faces can move on the canvas without moving out of the edge. The function random gives the rage for the movements of the images and the function if constrains them to fix on the canvas.

The benefits of the function array are: you can use a huge number of variables to control your function but also use certain defined variables at the same time. It makes the code easier to see. Also, compared with the function random, the function array gives a certain track for those images.

I would like to use the function array to draw a picture of snowing with a certain track. Because the number of snowflakes is big, and  I don’t want them to fall randomly but with a certain track, I then can use the function array to control my snowflakes and draw a beautiful picture.

link

Leave a Reply