Introduction:
For this recitation, we were tasked with creating an array. Similar to animation, I also find arrays a bit confusing so this recitation was very helpful.
My Array:
This is a video containing my array. I was unable to make it to step four as there was no time left in the recitation, however this is what I ended up with.
Code:
void setup () { size(600, 600); background(0); //drawNightmare(360, 240, color(120, 60, 0)); //drawNightmare(240, 420, color(140, 50, 32)); //drawNightmare(510, 140, color(240, 34, 88)); //for (int i=0; i<100; i++) { //drawNightmare(random(0, width), random(0, height), color(random (0, 255), random(0, 255), random(0, 255))); //} } void drawNightmare(float x, float y, color c) { fill(c); ellipse(x, y, 150, 150); fill(255); ellipse(x-25, y-15, 30, 20); ellipse(x+25, y-15, 30, 20); } void draw () { for (int i=0; i<100; i++) { drawNightmare(random(0, width), random(0, height), color(random (0, 255), random(0, 255), random(0, 255))); } }
Homework Questions:
Q1: In your own words, please explain the difference between having your for loop from Step 2 in setup()
as opposed to in draw()
.
Answer: While setup runs the code once, void draw runs it over and over again.
What is the benefit of using arrays? How might you use arrays in a potential project?
Arrays make it easy to deal animations containing a large number of different entities. This functions could be used to create complex patterns for future projects.