xxxxxxxxxx
51
let n = 80;
let widthMult = 3;
let heightMult = 6;
let shapes = [];
function setup() {
createCanvas(800, 800);
angleMode(DEGREES);
strokeWeight(3);
background(255, 255, 255, 100);
// Create an array of shape objects
for (let x = width; x > -n * widthMult; x -= n) {
for (let y = height; y > -n * heightMult; y -= n) {
let shape = {
x: x + n / 2,
y: y + n / 2,
size: n * floor(random(1, min(widthMult, heightMult))),
color: color(random(255), random(255), random(255)),
clicked: false,
};
shapes.push(shape);
}
}
}
function draw() {
for (let i = 0; i < shapes.length; i++) {
let shape = shapes[i];
push();
translate(shape.x, shape.y);
rotate(floor(random(8)) * 360);
if (dist(mouseX, mouseY, shape.x, shape.y) < shape.size / 2) {
if (mouseIsPressed) {
shape.color = color(random(255), random(255), random(255));
shape.size = n * floor(random(1, min(widthMult, heightMult)));
}
fill(255, 200);
} else {
noFill();
}
stroke(shape.color);
strokeWeight(3);
ellipse(0, 0, shape.size, shape.size);
pop();
}
}