xxxxxxxxxx
47
/*
this is a sketch to do boolean condition
this sketch turns background color into different ones
*/
let bgColor;
let colorText = "YELLOW";
let textColor;
let bgSwitch = true;
function setup() {
createCanvas(400, 400);
textAlign(CENTER);
bgColor = color(255, 255, 0);
}
function draw() {
textColor = color(0);
if (!bgSwitch) {
colorText = "RANDOM"
textColor = color(255);
} else {
bgSwitch = true;
colorText = "COLOR"
}
background(bgColor);
textSize(20);
fill(textColor);
text(colorText, width / 2, height / 2);
}
function mousePressed() {
if (bgSwitch) {
bgSwitch = false;
} else {
bgSwitch = true;
}
bgColor = color(random(255), random(255), random(255));
}