xxxxxxxxxx
41
// Example usage in p5.js sketch
let timer
let canvas
function setup() {
canvas = createCanvas(400, 400)
timer = new Timer()
timer.setCountDown(10) // Set countdown to 90 seconds (1:30)
timer.start()
}
function draw() {
background(0)
timer.draw()
if (timer.isFinished) {
console.log("Timer finished!")
// You can add any additional actions here when the timer finishes
fill(255);
noStroke();
textAlign(CENTER,CENTER);
text("Time is Up\nHit `r` to restart timer.", width/2, height/2 + 50);
}
}
function mousePressed() {
if (timer.isRunning) {
timer.stop()
} else {
timer.start()
}
}
function keyPressed() {
if (key === "r" || key === "R") {
timer.restart()
timer.setCountDown(90) // Reset to 90 seconds
}
}