2) if-else문


image.png

function setup() { createCanvas(400, 400); }

function draw() { background('gray'); if(mouseIsPressed){ fill(255,0,0); }else{ fill(255,255,255); } ellipse(width/2,height/2,200,200); }

image.png

let x=100, y=50, w=100, h=200;

function setup() { createCanvas(400, 400); }

function draw() { background('gray'); if(mouseX>x&&mouseX<x+w&&mouseY>y&&mouseY<y+h){ fill(255,0,0); }else{ fill(255,255,255); } rect(x,y,w,h); }

image.png

image.png