Recitation 7: Function and Arrays – Sagar Risal

Materials:

Processing App

Function and Arrays 

This recitation consisted of using the for statement and arrays. There was of course the simple coding of making the shapes, but then we experimented in how putting the for statements in different locations can change the way the code looks, by either not repeating or repeating multiple times.

Step 1: 

All I did in this step was create a rectangle under one void, so I could easily input the values that I wanted for the rectangle.

Recitation 7 – Step 1 Vid

Step 2: 

For this step I created the for loop to create the rectangles in different sizes and colors randomly around the screen. When I did this in setup, it worked fine, showing the 100 rectangles, but when I put it into draw it never stopped. The draw function repeatedly drew 100 rectangles constantly.   

Recitation 7 – Step 2 Vid

Recitation 7 – Step 2 pt.2 Vid

Step 3: 

For step 3 I had already created an array in step 2 so I didn’t need to change anything else. 

Step 4:

In step 4 i had to make the squares move while in the boundary of the screen, for this I used an if statement, so that the squares could bounce of the walls. All the other code stayed relatively the same, I just to adjust some of the x and y speeds. 

Recitation 7 – Step 4

Question 1: 

The difference that I found was that when I had the code in setup, it did the action and did not repeat. Loop on the other hand kept repeating and repeating. I understand this to mean that whatever you put in loops will consistently repeat, while in setup it will just one the code once and stay in that position.

Question 2:

Arrays are very useful for storing multiple variables and being able to easily access them. This would be very useful in a project with many different inputs or a lot of data, so that the data could be very easy to manipulate to what you want to do with it. 

Leave a Reply