Recitation 7 Documentation – Jackson Simon

This documentation asked us to create an image made up of different shapes, then to display that image 100 times. After that, to display the 100 times on an infinite loop (using draw() ). The main challenge of this recitation was to use certain functions (i.e. a for loop), and arrays. A for loop allows the user to repeat a certain task as many times as they want until the amount is met (without having to copy paste it the amount of times you want it executed). An array allows you store different values in a same variable, making the randomness (or specific randomness, depending on how you store the values in the Array) much easier.

I started by making a simple square, adding an ellipse and triangle as eyes, and a rectangle as a mouth. Then I executed the code so that it would display it 100 times, and keep display it 100 times on top of the last ones displayed, infinitely (while still staying within the sketch).

My code:

My code in action:

Question 1:

The difference between having the for loop in setup versus draw is relatively simple. When it is in setup() it creates the image 100 times and just displays it as such, when it is in draw() it creates the image 100 times over and over, displaying on top of the previous 100 images (unless background() is put into draw, in which case it will keep printing the 100 images but the previous 100 images will disappear).

Question 2:

The benefit of using arrays resides in the use of the same variable, but with different values. In simpler terms, it means that you can have a variable x (for example for a position), and if this variable is set to an array then you can have multiple x positions depending on your needs. You can specifically make x[1], x[2], x[3]  etc. whatever values you need and call on them when necessary; or make x[i], a large amount of x positions, and have them linked to one random value, which would make each x random.

You could potentially use arrays in serial communication, between Arduino and Processing, to allocate each sensor to a specific sensor[i]: rendering the calling on these sensors (in Processing specifically) easier. That is to say, instead of having to recreate values for each sensor, they get allocated to the specific sensor[i] to allow for the values to be transferable between both programs.

Leave a Reply