font.push(loadFont("NotoSerifJP-Medium.otf"));
font.push(loadFont("NotoSansJP-Medium.otf"));
json = loadJSON("yojijukugo.json", function() {
createCanvas(800*scl, 800*scl);
colorMode(HSB, 360, 100, 100, 100);
textAlign(CENTER, CENTER);
n = random() > 0.5 ? 1 : 0;
dc.shadowColor = color(0, 0, 0, 35);
dc.shadowBlur = offset / 5;
let w = sqrt(sq(width) + sq(height));
translate(width / 2, height / 2);
translate(-w / 2, -w / 2);
separateGrid(0, 0, w, w / 7);
function separateGrid(x, y, d, minD) {
let step = int(random(1, 6));
for (let j = 0; j < step; j++) {
for (let i = 0; i < step; i++) {
if (random(100) < 90 && dw > minD) {
separateGrid(cx, cy, dw, minD);
while (typeof str == "undefined" || str == null) {
let json_length = Object.keys(json).length;
let num = int(random(json_length));
drawYojiJukugo(cx + dw / 2, cy + dw / 2, dw, str);
function drawYojiJukugo(cx, cy, d, str) {
let isBold = random(100) > 50;
let isSerif = random(100) > 50;
for (let i = 0; i < str.length; i++) {
let chr = str.substr(i, 1);
let g = createGraphics(e, e);
g.textAlign(CENTER, CENTER);
g.text(chr, e / 2, e / 2-e/5);
let ratio_ax = random(ratio, 1 - ratio);
let ratio_bx = 1 - ratio_ax;
let ratio_ay = random(ratio, 1 - ratio);
let ratio_by = 1 - ratio_ay;
let ratio_cy = random(ratio, 1 - ratio);
let ratio_dy = 1 - ratio_cy;
translate(-d / 2, -d / 2);
image(graphics[0], d * ratio_ax, 0, d * ratio_bx, d * ratio_ay);
image(graphics[1], d * ratio_ax, d * ratio_ay, d * ratio_bx, d * ratio_by);
image(graphics[2], 0, 0, d * ratio_ax, d * ratio_cy);
image(graphics[3], 0, d * ratio_cy, d * ratio_ax, d * ratio_dy);