xxxxxxxxxx
34
function setup() {
createCanvas(400, 400);
//setting the frame rate to 5 frames per sec to make the shake visible
frameRate(5);
}
function draw() {
//setting the background color for each frame randomly whilst making it transparent by adding the forth argument to "50"
background(random(255), random(255), random(255), 50);
//adding the loop
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);
noStroke();
strokeWeight(0.5);
rect(x, y, 40, 40); // Draw squares instead of circles
// Inner squares that "shake"
noStroke();
fill(random(255), random(255), random(255), 50); // Random colors for each frame
strokeWeight(0.5);
// Adding random movement to simulate shaking
let randomShakeX = random(-3, 3); // Small random offset for shaking
let randomShakeY = random(-3, 3); // 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
}
}
}