xxxxxxxxxx
34
/*
There are different ways to handle the timing of events
One way is to use the p5 function millis() which returns the amount of time that has passed, in milliseconds, since the sketch started
1 second == 1000 milliseconds
https://p5js.org/reference/#/p5/millis
*/
let timer = 0;
let interval = 2000 // 2 seconds
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
// console.log(millis());
// if the amount of time that
// has passed is greater than the
// interval, execute the code
// in the conditional statement
if (millis() - timer > interval) {
console.log('do something')
// reset the timer to equal
// the current number of milliseconds
timer = millis();
}
}