xxxxxxxxxx
31
function setup() {
createCanvas(400, 400);
frameRate(5); // Set frame rate to control animation speed
}
function draw() {
background(random(255), random(255), random(255), 50); // Random colors for each frame
for (let x = 0; x <= width; x += 40) {
for (let y = 0; y <= height; y += 40) {
// Outer square with random colors
fill(random(255), random(255), random(255), 50);
stroke('rgb(0,0,255)');
strokeWeight(0.2);
rect(x, y, 40, 40); // Draw squares instead of circles
// Inner squares that "shake"
stroke('blue');
fill(random(255), random(255), random(255), 50); // Random colors for each frame
strokeWeight(0.2);
// Adding random movement to simulate shaking
let randomShakeX = random(-2, 4); // Small random offset for shaking
let randomShakeY = random(-2, 4); // Small random offset for shaking
rect(x + randomShakeX, y + randomShakeY, 30, 30); // First inner square shakes
rect(x + randomShakeX, y + randomShakeY, 20, 20); // Second inner square shakes
rect(x + randomShakeX, y + randomShakeY, 10, 10); // Third inner square shakes
}
}
}