xxxxxxxxxx
34
// conditionals
// by Yatharth
// This code is based on everything I learned from
// Daniel Shiffman (https://thecodingtrain.com)
let day = true;
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
// if it is day, fill the background with white
if (day) {
background(255);
fill(0);
} else { // else it is night, fill the background with black
background(0);
fill(255);
}
// displaying the text on the screen
textAlign(CENTER);
textSize(30);
text("Press mouse button to interact", width / 2, height / 2);
}
function mousePressed() {
// inverting the 'day' variable
// day = true -> day = false
// day = false -> day = true
day = !day;
}