Worksheet Q2

Divide the canvas into 3 columns with rect()s. When you mouse over a column, it appears and stays until the next time you mouse over it again, at which point the column disappears. (Just get this working for one column.)

It’s probably wrong, but just to see

Gut reaction was that it needs a boolean variable to remember the state of the rectangle. If the state is ON, rectangle appears. And when mouse enters the rectangle, the state changes.

The rectangle is blinking because the when mouseX is greater than 400, the ON state keeps flipping. Therefore I cannot just use mouseX for the condition statement, it needs to remember a state.

take 1.mov

Decomposing the problem:

IMG_2041.heic

t mouseX state of rectangle
1 in on
1 out on
2 in off
2 out off
3 in on
3 out on

The rectangle appears if:

Therefore I will need at least two boolean variables to remember the state of the above two things. And when both conditions are met, the rectangle appears.

Sequence of events:

  1. mouseX enters rectangle —> flip the state of rectangle
  2. mouseX leaves rectangle —> keep the state of rectangle

I need boolean variables to remember the state of two things:

Event 1 - mouseX enters the rectangle