createCanvas(windowWidth, windowHeight);
background(color('#EAE2B7'));
let squareSize = min(width, height) - margin * 2;
let startX = (width - squareSize) / 2;
let startY = (height - squareSize) / 2;
let start = color('#003049');
let end = color('#D62828');
drawCheckerBox(startX, startY, squareSize, squareSize, 7, start, end, 3);
const drawCheckerBox = (x, y, w, h, n, clr1, clr2, depth) => {
let cirClr1 = color('#F77F00');
let cirClr2 = color('#FCBF49');
for (let j = 0; j < n; j++) {
for (let k = 0; k < n; k++) {
if (depth <= 0 || random() < 0.9) {
let clr = cnt % 2 == 0 ? clr1 : clr2;
translate(j * w_diff, k * h_diff);
rect(0, 0, w_diff, h_diff);
ellipse(0, 0, w_diff, h_diff);
ellipse(0, 0, w_diff, h_diff);
circlePack(w_diff, h_diff, 100, cirClr1, cirClr2);
drawCheckerBox(j * w_diff, k * h_diff, w_diff, h_diff, Math.floor(Math.random() * 5) * 2 + 3, clr1, clr2, depth - 1);
function circlePack(w, h, maxAttempts, clr1, clr2) {
let minRadius = minDim * 0.05;
let maxRadius = minDim * 0.15;
let outerRadius = minDim / 2;
while (attempts < maxAttempts) {
let angle = random(TWO_PI);
let distance = random(outerRadius - maxRadius);
let radius = random(minRadius, maxRadius);
x: centerX + cos(angle) * distance,
y: centerY + sin(angle) * distance,
for (let circle of circles) {
let d = dist(newCircle.x, newCircle.y, circle.x, circle.y);
if (d < newCircle.r + circle.r) {
for (let i = 0; i < circles.length; i++) {
fill(i % 2 == 0 ? clr1 : clr2);
ellipse(circle.x, circle.y, circle.r * 2, circle.r * 2);