xxxxxxxxxx
36
let colX = [];
let colColors = [];
let turnRed = [];
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 10; i++) {
colX[i] = i * (width / 10);
colColors[i] = color("white");
turnRed[i] = false;
}
}
function draw() {
background(220);
for (let i = 0; i < 10; i++) {
if (turnRed[i]) {
colColors[i] = color("red");
} else {
colColors[i] = color("white");
}
fill(colColors[i]);
rect(colX[i], 0, width / 10, height);
}
}
function mousePressed() {
for (let i = 0; i < 10; i++) {
if (mouseX > colX[i] && mouseX < colX[i] + 40) {
turnRed[i] = !turnRed[i];
}
}
}