2) if-else문


Untitled

Untitled

3) if-else if문


Untitled

Untitled

function setup() {
  createCanvas(400, 400);
}
function draw() {
  background(0);
  fill(255,255,0);
  if(mouseX<width/2 &&mouseY<height/2){
    rect(0,0,width/2,height/2);
  }else if(mouseX>width/2 && mouseY<height/2){
    rect(width/2,0,width/2,height/2);        
  }else if(mouseX<width/2 && mouseY>height/2){
    rect(0,height/2,width/2,height/2);       
  }else{
    rect(width/2,height/2,width/2,height/2);      
  }
}

Untitled