canvas = {
const context = DOM.context2d(width, height);
while (true) {
context.fillStyle = "#00000002";
context.fillRect(0, 0, width, height);
context.beginPath();
for (const cell of voronoi.cellPolygons()) {
const [x, y, r] = polygonIncircle(cell);
if (r < 1.5) continue;
context.moveTo(x + r - 1.5, y);
context.arc(x, y, r - 1.5, 0, 2 * Math.PI);
}
context.fillStyle = "#fff";
context.fill();
context.beginPath();
context.strokeStyle = "#bbb";
context.stroke();
context.beginPath();
context.fillStyle = "#000";
context.fill();
yield context.canvas;
for (let i = 0; i < n; ++i) {
const x = i << 1;
const y = x + 1;
positions[x] += velocities[x];
positions[y] += velocities[y];
if (positions[x] < -margin) positions[x] += width + margin * 2;
else if (positions[x] > width + margin) positions[x] -= width + margin * 2;
if (positions[y] < -margin) positions[y] += height + margin * 2;
else if (positions[y] > height + margin) positions[y] -= height + margin * 2;
velocities[x] += 0.2 * (Math.random() - 0.5) - 0.01 * velocities[x];
velocities[y] += 0.2 * (Math.random() - 0.5) - 0.01 * velocities[y];
}
voronoi.update();
}
}