{
replay;
await visibility();
const size = Math.min(width, 512);
const ratio = size / tileSize;
const ctx = DOM.context2d(size, size, 2);
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, size, size);
ctx.globalAlpha = 0.5;
ctx.drawImage(terrainViz, 0, 0, size, size);
ctx.globalAlpha = 1;
function drawLine(ax, ay, bx, by, color) {
ctx.beginPath();
ctx.moveTo(ax * ratio, ay * ratio);
ctx.lineTo(bx * ratio, by * ratio);
ctx.strokeStyle = color;
ctx.stroke();
}
function* split(ax, ay, bx, by, cx, cy) {
const mx = (ax + bx) >> 1;
const my = (ay + by) >> 1;
if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * (tileSize + 1) + mx] > 100) {
drawLine(mx, my, cx, cy, 'red');
yield ctx.canvas;
yield* split(cx, cy, ax, ay, mx, my);
yield* split(bx, by, cx, cy, mx, my);
drawLine(mx, my, cx, cy, 'black');
}
}
drawLine(0, 0, tileSize, tileSize, 'red');
yield* split(0, 0, tileSize, tileSize, tileSize, 0, 0);
yield* split(tileSize, tileSize, 0, 0, 0, tileSize, 0);
drawLine(0, 0, tileSize, tileSize, 'black');
}