Code

boolean box;

void setup () {
  size (400, 400);
  background (127);
  rect (150, 150, 100, 100);
  box = false;
  
}

void loop(){

  fill (255);
  if (box() == true){
    fill (255, 255, 0);
    rect (150, 150, 100, 100);
  }
  if ((mousePressed == true) && (box() == true)){
    fill (0);
  } 
  rect (150, 150, 100, 100);
}

boolean box (){
  if    ((mouseX < 250)
  && (mouseX >= 150)
  && (mouseY < 250)
  && (mouseY >= 150))
{return true;}
else {return false;}}

005 -- Conditional Testing in Interactivity: A Classic Button

Statement:Modify your square from Assignment #004, such that it becomes a button with a "hover" state: White when inactive; Yellow when the user is hovering over it (mouseDown is false); Black when the user is holding the mouse down inside of it; and which returns to white thereafter.


Pete_Assignment_5

hide statement