xxxxxxxxxx
51
let colors;
let gridSize = 5;
let cellSize;
function setup() {
createCanvas(600, 600);
colors = [
color(230, 230, 250), // Lavender
color(255, 182, 193), // Pastel Pink
color(0), // Black
color(255) // White
];
cellSize = width / gridSize;
noLoop();
}
function draw() {
background(255);
for (let i = 0; i < gridSize; i++) {
for (let j = 0; j < gridSize; j++) {
drawConcentricSquares(i * cellSize, j * cellSize, cellSize);
}
}
}
function drawConcentricSquares(x, y, size) {
let numSquares = floor(random(3, 8));
let squareSize = size;
let colorIndex1 = floor(random(colors.length));
let colorIndex2 = floor(random(colors.length));
while (colorIndex2 === colorIndex1) {
colorIndex2 = floor(random(colors.length));
}
for (let i = 0; i < numSquares; i++) {
if (i % 2 === 0) {
fill(colors[colorIndex1]);
} else {
fill(colors[colorIndex2]);
}
noStroke();
rect(x + (size - squareSize) / 2, y + (size - squareSize) / 2, squareSize, squareSize);
squareSize -= size / numSquares;
}
}
function mousePressed() {
redraw();
}