Code

void setup(){
  size(400,400);
  rectMode(CORNER);
  fill(255);
}

int rw = 100;
int rh = 100;
int rx = 150;
int ry = 150;

boolean black = false;

void loop(){
  background(127);
  noStroke();
  rect(rx,ry,rw,rh);
}

void mousePressed(){
  if(mouseX>rx&&mouseX<rx+rw&&mouseY>ry&&mouseY<ry+rh){
    if(!black){
      fill(0);
      black = true;
    }
  }
}

001 -- Conditional Testing in Interactivity: Using IF

Statement:All of the assignments for this week will require applets that are 400x400 pixels, with a 100x100 pixel square centered in the middle.

For each assignment, be sure to upload a 100x100 pixel icon for your project. Test to make sure your work has uploaded properly!

On a grey background, place a square of 100x100 pixels. Create an interaction such that, if the user clicks in the square, it turns black, and stays that way.

hide statement