canvas = {
const context = DOM.context2d(width, height);
while (true) {
context.save();
context.beginPath();
voronoi.render(context);
context.lineWidth = 2;
context.strokeStyle = "white";
context.stroke();
context.lineWidth = 1;
context.strokeStyle = "red";
context.stroke();
context.restore();
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();
}
}