Assignment 4: Loops

https://editor.p5js.org/ltomlinson/sketches/_wnwY1SYD

https://editor.p5js.org/ltomlinson/sketches/_wnwY1SYD

For this assignment, I made a grid like structure inspired by the Lite-Brite to demonstrate the functionality of loops. I created a “Peg” object and a “pegs” array, then a function that filled the “pegs” array with new “Peg” objects based on a “gridSize” variable. Then, in the draw function, I wrote a for loop that iterates through the “pegs” array, drawing each “Peg” object.

Additionally, you can click each peg to change its color. Because the pegs are circular, I used a function to calculate the distance of the mouse from the center of each peg, and an if statement that checks if the distance is less than the radius of the peg.

Et voila! Check it out here.

Previous
Previous

Assignment 5: Functions/Glitch

Next
Next

Assignment 3: Buttons