This week’s worksheet was slightly less difficult than last weeks but I still struggled with #2.
I was having a hard time finding a way for the mouse to remember that it has crossed over to the red column once already and initially I was trying to create a variable called “old” so that when the mouse crossed back over to the grey area it would trigger a state change and the next time it crossed into the red the turning-off-light condition would be that the mouse must’ve been in the “old” state once already. However, the issue became that the status wouldn’t reset after the light has been turned off once.
With some help from my peers, I eventually I learned that for the mouse to remember its last location I needed an equation “previous_mouse = mouseX”. And by writing that line when I cross the boundary there is a distinction between the mouse’s last position in the previous frame and the mouse’s current position, which is now inside the boundary. By using a toggle “On = !On” it allowed for the light to be turned on and off instead of just on and needing a separate line for turning it off.
For the group creative assignment we created four quadrants that drew different shapes as the mouse moved. By using one variable “rr” in the relationship between the shapes in three of the quadrants and having one increase in value while the other decreases it created an interesting variation in sizes as you move the mouse across the quadrants. And I added a function to reset the canvas when you click the mouse.
The mousePressed function was kind of confusing to use as I didn’t realize you had to put it outside the draw function in order for it to execute. But now I know.