xxxxxxxxxx
function setup() {
createCanvas(800, 800);
colorMode(HSB, 360, 100, 100, 100);
angleMode(DEGREES);
}
function draw() {
background(0, 0, 90);
let offset = width / 15;
let x = offset;
let y = offset;
let d = width - offset * 2;
let minD = d / 8;
drawingContext.shadowColor = color(0, 0, 0, 33);
drawingContext.shadowBlur = offset / 3;
noStroke();
separateGrid(x, y, d, minD);
noLoop();
}
function separateGrid(x, y, d, minD) {
let sep = int(random([1, 2, 4]));
let w = d / sep;
for (let j = 0; j < sep; j++) {
for (let i = 0; i < sep; i++) {
let nx = x + i * w;
let ny = y + j * w;
if (random() < 0.9 && w > minD) {
separateGrid(nx, ny, w, minD);
} else {
drawPattern(nx + w / 2, ny + w / 2, w, 3,int(random(2, 8)));
}
}
}
}
function drawPattern(x, y, d, cells) {
let isVertical = random() > 0.5;
push();
translate(x, y);
rotate((int(random(4)) * 360) / 4);
// rect(0, 0, d, d);
push();
triangle(-d / 2, -d / 2, d / 2, -d / 2, -d / 2, d / 2);
drawingContext.clip();
if (isVertical) {
translate(-d / 2, -d / 2);
}
for (let i = 0; i < cells; i++) {
if (i % 2 == 0) {
fill(0);
} else {
fill(255);
}
if (isVertical) {
rectMode(CORNER);
rect((d / cells) * i, 0, d / cells, d);
} else {
rectMode(CENTER);
rect(0, 0, d - (i / cells) * d);
}
}
pop();
push();
triangle(d / 2, d / 2, d / 2, -d / 2, -d / 2, d / 2);
if (isVertical) {
translate(-d / 2, -d / 2);
}
drawingContext.clip();
for (let i = 0; i < cells; i++) {
if (i % 2 == 1) {
fill(0);
} else {
fill(255);
}
rectMode(CENTER);
if (isVertical) {
rectMode(CORNER);
rect((d / cells) * i, 0, d / cells, d);
} else {
rectMode(CENTER);
rect(0, 0, d - (i / cells) * d);
}
}
pop();
pop();
}