xxxxxxxxxx
34
let timerValue = 7 * 60; // 7 minutes in seconds
function setup() {
createCanvas(1920, 1080);
textAlign(CENTER, CENTER);
textSize(500);
}
function draw() {
background(220);
// Calculate minutes and seconds from timerValue
let minutes = floor(timerValue / 60);
let seconds = timerValue % 60;
// Display the timer value in M:SS format
text(minutes + ':' + nf(seconds, 2), width / 2, height / 2);
// When the timer reaches 0, stop the sketch
if (timerValue <= 0) {
noLoop();
text("Time's up!", width / 2, height / 2 + 60);
}
}
function timeIt() {
if (timerValue > 0) {
timerValue--;
}
}
// Call the timeIt function every 1000 milliseconds (1 second)
setInterval(timeIt, 1000);