xxxxxxxxxx
73
const columns = 5;
const rows = 5;
let cellWidth;
let cellHeight;
function setup() {
createCanvas(425, 425);
cellWidth = width / columns;
cellHeight = height / rows;
noFill();
background(32);
stroke(255);
for (let c = 0; c < columns; c++) {
for (let r = 0; r < rows; r++) {
const cellX = c * cellWidth;
const cellY = r * cellHeight;
drawCell(cellX, cellY);
}
}
frameRate(10);
}
function draw() {
const c = int(random(columns));
const r = int(random(rows));
const cellX = c * cellWidth;
const cellY = r * cellHeight;
drawCell(cellX, cellY);
}
function drawCell(x, y) {
noStroke();
fill(32);
rect(x, y, cellWidth, cellHeight);
noFill();
const squareCount = 10;
const randomOffset = 5;
for (let i = 1; i <= squareCount; i++) {
const layerOffset = 5 * i;
const xOne = x + layerOffset + random(-randomOffset, randomOffset);
const yOne = y + layerOffset + random(-randomOffset, randomOffset);
const xTwo =
x + cellWidth - layerOffset + random(-randomOffset, randomOffset);
const yTwo = y + layerOffset + random(-randomOffset, randomOffset);
const xThree =
x + cellWidth - layerOffset + random(-randomOffset, randomOffset);
const yThree =
y + cellHeight - layerOffset + random(-randomOffset, randomOffset);
const xFour = x + layerOffset + random(-randomOffset, randomOffset);
const yFour =
y + cellHeight - layerOffset + random(-randomOffset, randomOffset);
stroke(random(256), random(256), random(256));
quad(xOne, yOne, xTwo, yTwo, xThree, yThree, xFour, yFour);
}
}