xxxxxxxxxx
let state = 1;
let drawRed;
let drawGreen;
let drawBlue;
let btnD = 80;
let btnBarY = 100;
let redBtnX = 200;
let greenBtnX = 300;
let blueBtnX = 400;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
drawRed = color(220,30,40);
drawGreen = color(150,200,35);
drawBlue = color(65,65,220);
noStroke();
}
function draw() {
fill(drawRed);
ellipse(redBtnX, btnBarY, btnD, btnD);
fill(drawGreen);
ellipse(greenBtnX, btnBarY, btnD, btnD);
fill(drawBlue);
ellipse(blueBtnX, btnBarY, btnD, btnD);
if (state == 1){
fill(drawRed);
} else if (state == 2){
fill(drawGreen);
} else if (state == 3){
fill(drawBlue);
}
}
function mouseDragged() {
ellipse(mouseX, mouseY, 15, 15);
}
function mousePressed (){
if (dist(mouseX, mouseY, redBtnX, btnBarY) < btnD/2) {
state = 1;
} else if (dist(mouseX, mouseY, greenBtnX, btnBarY) < btnD/2) {
state = 2;
} else if (dist(mouseX, mouseY, blueBtnX, btnBarY) < btnD/2) {
state = 3;
}
}
function keyTyped(){
if(key===" "){
background(255);
}
}