xxxxxxxxxx
40
// Reliable bite
//
// Jared Donovan 2022
//
// Shows how to move text on an interval.
let lastBiteTime = 0;
let timeBetweenBites = 1200;
let bitePosn = 40;
function setup() {
createCanvas(400, 400);
textSize(30);
textAlign(CENTER, CENTER);
background(220);
}
function draw() {
let timeNow = millis();
let timeSinceLastBite = timeNow - lastBiteTime;
// If it has been longer than timeBetweenBites, then
// draw the text 'bite' at a new position on the canvas.
if (timeSinceLastBite > timeBetweenBites){
background(220);
text('BITE', bitePosn, bitePosn);
// update the last bite time to record time now
lastBiteTime = timeNow;
// Make it so next bite is further down.
bitePosn += 40;
// If it goes off the bottom, wrap to top
if (bitePosn > height - 40){
bitePosn = 40;
}
}
}