xxxxxxxxxx
33
let colors = ['RED', 'YELLOW', 'BLUE', 'WHITE'];
let currentIndex = 0
function setup() {
createCanvas(800, 800);
displayPage();
}
function draw() {
//stuff can be added here
}
function mouseClicked() {
if (mouseX > 20 && mouseX < 120 && mouseY > 200 && mouseY < 300) {
if (colors[currentIndex] === 'RED') {
currentIndex = (currentIndex + 1) % colors.length;
displayPage();
}
}
}
function displayPage() {
background(255);
// red box
fill(255, 0, 0);
rect(20, 200, 100, 100);
// text next to the red box
fill(0);
textSize(24);
text(colors[currentIndex], 150, 250);
}