Concept
For this assignment, I took inspiration from the computer graphics pdf attached to this assignment’s description (photo below).
Building on this graphic, I made a simple grid with squares inside it. I initially wanted to create the moving graphics, but I could not figure out how. Therefore, I decided to use some skills we learned in class on changing colors when the mouse is inside the squares. Finally, I ended up with my final design, where the group of squares changes to the colors of the rainbow when the mouse hovers over them, keeping all the other cells still white.
Here is my final sketch:
Code I am Proud of:
for (let r = 0; r < 5; r++) {
for (let c = 0; c < 7; c++) {
//calculates where each cell should start based on the row and column and shifts by cell size
let cellX = c * 80;
let cellY = r * 80;
square(cellX, cellY, 80);
square(cellX + 10, cellY + 10, 60);
square(cellX + 20, cellY + 20, 40);
square(cellX + 30, cellY + 30, 20);
}
}
I am particularly proud of my code which creates the grid, because I optimized it. Initially, I set up the grid with four different for() loops, which basically keep printing a grid but make it smaller each time to create the inner squares effect. Then, I realized I could combine them all into a single for loop by storing each outer square’s starting X and Y locations, and then writing multiple square() functions, shifting each one according to how inner the square is. This also allowed me to select a different color for each square when the mouse hovers over it.
Reflection and Future Improvements:
Overall, I am quite happy with my sketch and enjoyed the process of creating it. For the future, I would definitely like to implement some automatic motion into my sketch. I would probably want to recreate the original sketch I took inspiration from, with the moving inner squares. Additionally, I would like to work on a second version of this sketch where the color of the inner squares only changes if the mouse is directly over it, not if the mouse is generally inside any of the squares within that group of squares.
