{
regenerate;
const width = 640,
height = 640,
cols = 8,
rows = 8,
margin = 5,
cellWidth = width / cols,
cellHeight = height / rows,
squares = fillWithSquares(cols, rows),
colors = await patterns(palettes[selectPalette]),
shapes = [rect, circle, diamond, x],
n = colors.length,
m = shapes.length;
function draw(app) {
app.append(cm.clear, { fill: background });
app
.data(squares)
.append(cm.group, {
x: (d) => d.col * cellWidth + margin,
y: (d) => d.row * cellHeight + margin
})
.append(cm.path, {
d: (d) => {
const size = d.size * cellWidth - margin * 2;
const path = shapes[cm.randomInt(0, m)];
const ctx = cm.pathContext();
path(ctx, 0, 0, size, size);
return ctx.toArray();
},
fill: (d) => colors[cm.randomInt(0, n)],
stroke: "black",
strokeWidth: 2
});
}
function dispose(app) {
invalidation.then(() => app.dispose());
}
return cm.app({ width, height }).call(draw).call(dispose).start().node();
}