canvas = {
const n = 500 << 1;
const points = Float64Array.from({length: n}, (_, i) => Math.random() + (i & 1 ? height : width) / 2);
const delaunay = new d3.Delaunay(points);
const context = DOM.context2d(width, height);
context.lineCap = "square";
const voronoi = delaunay.voronoi([0, 0, width, height]);
for (let i = 0; i < 1200; ++i) {
context.clearRect(0, 0, width, height);
context.beginPath();
voronoi.render(context);
context.strokeStyle = "red";
context.stroke();
context.beginPath();
for (let i = 0; i < n; i += 2) {
const cell = voronoi.cellPolygon(i >> 1);
if (cell === null) continue;
const x0 = points[i], y0 = points[i + 1];
const [x1, y1] = d3.polygonCentroid(cell);
context.moveTo(x0, y0);
context.lineTo(points[i] = x0 + (x1 - x0) * omega, points[i + 1] = y0 + (y1 - y0) * omega);
}
context.strokeStyle = "black";
context.stroke();
yield context.canvas;
voronoi.update();
}
}