xxxxxxxxxx
41
//turn on light
var on = false;
function setup() {
createCanvas(600, 400);
// Starting location
x = 300;
y = 200;
// Dimensions
w = 100;
h = 100;
}
function draw() {
if(on){
background(0,0,255);
}else {
background(0);
}
stroke(225);
strokeWeight(4);
noFill();
//rollover-rect changes color when mouse is inside
if(mouseX > 250 && mouseX < 350 &&mouseY >150 && mouseY < 250){
fill(0,0,255);
}
rectMode(CENTER)
rect(x,y,w,h);
}
//when mouse is pressed, set the backgrounds blue,red, green.
function mousePressed(){
if(mouseX > 250 && mouseX < 350 &&mouseY >150 && mouseY < 250)
on=!on;
fill(255,0,0);
rectMode(CENTER)
rect(x,y,w,h);
}