xxxxxxxxxx
32
let cellSize = 40;
let speed = 2;
let offset = 0;
function setup() {
createCanvas(400, 400);
noStroke();
frameRate(30);
}
function draw() {
background(255); // Clear the background on each frame
offset += speed; //
// offset cell size reset the loop
if (offset > cellSize) {
offset = 0;
}
for (let y = 0; y < height / cellSize; y++) {
for (let x = 0; x < width / cellSize; x++) {
let posX = x * cellSize + offset; //horizontal movement
let posY = y * cellSize;
fill(random(255), random(255));
//redraw the circle
ellipse(posX - cellSize, posY, cellSize * 0.8, cellSize * 0.8);
}
}
}