xxxxxxxxxx
// By Roni Kaufman
// https://ronikaufman.github.io
// https://twitter.com/KaufmanRoni
function setup() {
createCanvas(500, 500);
noLoop();
}
function draw() {
let margin = 50;
let n = 5;
let s = (width-2*margin)/n;
let palette = ["#6190d3", "#fcd494", "#f4b804"];
background("#fcf7ed");
let d1 = 0;
let d2 = s/2;
if (random() < 1/2) {
[d1, d2] = [d2, d1];
}
noStroke();
for (let x = margin+d1; x < width-margin-d1; x += s) {
for (let y = margin+d1; y < height-margin-d1; y += s) {
fill(random(palette));
makeTile(x, y, s);
}
}
noFill();
stroke("#044e9e");
strokeWeight(4);
for (let x = margin+d2; x < width-margin-d2; x += s) {
for (let y = margin+d2; y < height-margin-d2; y += s) {
makeTile(x, y, s);
}
}
}
function makeTile(x, y, s) {
beginShape();
vertex(x+s/2, y);
if (random() < 1/2) vertex(x+s, y);
vertex(x+s, y+s/2);
if (random() < 1/2) vertex(x+s, y+s);
vertex(x+s/2, y+s);
if (random() < 1/2) vertex(x, y+s);
vertex(x, y+s/2);
if (random() < 1/2) vertex(x, y);
endShape(CLOSE);
}