xxxxxxxxxx
// By Roni Kaufman
// https://ronikaufman.github.io
// Made for Genuary 2025
// Day 29: Grid-based graphic design.
function setup() {
createCanvas(500, 500);
pixelDensity(4);
strokeJoin(MITER);
frameRate(1);
frameCount = -1;
}
function draw() {
background("#fffbe6");
let margin = 18;
let u = (width-2*margin)/58;
let gap = 2*u;
noStroke();
let palette = ["#ef562f", "#fc8405", "#f9d531"];
let n = 1 +frameCount%6;
let s = (width-2*margin-(n-1)*gap)/n;
let colorGrid = [Array(n)].map((e) => Array(n));
for (let i = 0; i < n; i++) {
let x = margin + i*(s+gap);
for (let j = 0; j < n; j++) {
let y = margin + j*(s+gap);
let neighborColors = [];
if (i > 0) neighborColors.push(colorGrid[i-1][j]);
if (j > 0) neighborColors.push(colorGrid[i][j-1]);
let col;
do {
col = random(palette);
} while (neighborColors.indexOf(col) != -1)
colorGrid[i][j] = col;
fill(col);
square(x, y, s);
}
}
stroke(5);
strokeWeight(1.5);
noFill();
for (let n = 1; n < 7; n++) {
let s = (width-2*margin-(n-1)*gap)/n;
for (let x = margin; x < width-margin; x += s+gap) {
for (let y = margin; y < height-margin; y += s+gap) {
square(x, y, s);
}
}
}
}