xxxxxxxxxx
28
let lastDrawTime = 0; // time of the last rectangle drawn
let interval = 500; // interval in milliseconds for drawing rectangles
function setup() {
createCanvas(600, 400);
}
function draw() {
background(220);
let currentTime = millis(); // get the current time
// check if enough time has passed
if (currentTime - lastDrawTime >= interval) {
// update the last draw time
lastDrawTime = currentTime;
// draw a rectangle at a random position
let rectX = random(width);
let rectY = random(height);
let rectWidth = 50;
let rectHeight = 30;
fill(100, 150, 250); // set rectangle color
rect(rectX, rectY, rectWidth, rectHeight); // draw the rectangle
}
}