Code

void setup () {
  size (400, 400);
  background (60);
}

void loop() {
  if (mouseX >= 150
  && mouseX <= 250
  && mouseY >= 150
  && mouseY <= 250
  && mousePressed == true)
  {
    fill (0);
  }
  else
  {
    fill(255);
  }
  rect(150, 150, 100, 100);
}

004 -- Conditional Testing in Interactivity: State Machines II

Statement:Create a reactive square, such that the square turns black only while the user's mousebutton is down, AND the user's cursor is inside the square; if the user exits the square or releases the button, the square reverts to white. Decide whether it feels better to require that the initial click happen inside the square, or whether it can happen anywhere in the frame.


1:52am

hide statement