xxxxxxxxxx
let rects = [];
function setup() {
createCanvas(windowWidth * 0.4, windowHeight);
background(0, 0, 0);
frameRate(60);
}
function draw() {
stroke(random(0, 255), random(0, 255), random(0, 255));
strokeWeight(random(0, 50));
let color = [random(0, 255), random(0, 255), random(0, 255)];
let rectWidth = 100;
let rectHeight = random(0, 1000);
let xPos = random(0, 1000 - rectWidth);
rects.push({ x: xPos, y: 100, width: rectWidth, height: rectHeight, color: color });
for (let i = 0; i < rects.length; i++) {
let rect = rects[i];
fill(rect.color[0], rect.color[1], rect.color[2]);
window.rect(rect.x, rect.y, rect.width, rect.height); // use "rect" as a global variable
}
}
function update() {
for (let i = 0; i < rects.length; i++) {
rects[i].x += 2;
}
}
setInterval(update, 1000/60);