createCanvas(800, 800, WEBGL);
colorMode(HSB, 360, 100, 100, 100);
ortho(-width / 2, width / 2, -height / 2, height / 2, -2000, 2000);
palette = shuffle(chromotome.get().colors);
if (frameCount % (360 * 3) == 0) {
palette = shuffle(chromotome.get().colors);
randomSeed(100 + frameCount / (360 * 3));
directionalLight(color(0, 0, 80), 1, 0, -1);
directionalLight(color(0, 0, 30), -1, 0, -1);
directionalLight(color(0, 0, 50), 0, 1, 0);
translate(-d / 2, 0, -d / 2);
separateGrid(x, y, z, d, minD);
function separateGrid(x, y, z, d, minD) {
let sep = int(random(2, 5));
for (let j = 0; j < sep; j++) {
for (let i = 0; i < sep; i++) {
if (random(100) < 95 && w > minD) {
separateGrid(nx, 0, nz, w, minD);
let h = random(minD / 5, d);
translate(nx + w / 2, ny, nz + w / 2);
drawBuilding(w * 0.9, h, w * 0.9);
function drawBuilding(w, h, d) {
let colors = shuffle(palette.concat());
rotateY((int(random(4)) * 360) / 4);
let w_num = int(random(2, 6));
let w_margin = w_offset / 5;
let nw = (w - w_offset * 2 - w_margin * (w_num - 1)) / w_num;
let h_margin = w_offset / 5;
let h_num = int((w_num * h) / w);
let nh = (h - h_offset * 2 - h_margin * (h_num - 1)) / h_num;
translate(-w / 2, -h / 2, d / 2 + 1);
for (let j = 0; j < h_num; j++) {
for (let i = 0; i < w_num; i++) {
let nx = w_offset + i * (w_margin + nw);
let ny = h_offset + j * (h_margin + nh);
translate(-w / 2, -h / 2, -d / 2 - 1);
for (let j = 0; j < h_num; j++) {
for (let i = 0; i < w_num; i++) {
let nx = w_offset + i * (w_margin + nw);
let ny = h_offset + j * (h_margin + nh);
translate(-w / 2 - 1, -h / 2, -d / 2);
for (let j = 0; j < h_num; j++) {
for (let i = 0; i < w_num; i++) {
let nx = w_offset + i * (w_margin + nw);
let ny = h_offset + j * (h_margin + nh);
translate(+w / 2 + 1, -h / 2, d / 2);
for (let j = 0; j < h_num; j++) {
for (let i = 0; i < w_num; i++) {
let nx = w_offset + i * (w_margin + nw);
let ny = h_offset + j * (h_margin + nh);