Assignment 4: Loops
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.