animation = {
const n = 50;
const pad = 2;
const data = d3.range(n).map((i) => ({ r: i }));
const simulation = d3
.forceSimulation(data)
.force("x", d3.forceX())
.force("y", d3.forceY())
.force(
"collide",
d3.forceCollide((d) => d.r)
)
.stop();
let s = 500;
let svg = d3.create("svg").attr("width", s).attr("height", s);
let g = svg.append("g").attr("transform", `translate(${s / 2}, ${s / 2})`);
let circs = g
.selectAll("circle")
.attr("fill", "black")
.data(data)
.join("circle")
.attr("r", (c) => 0.9 * c.r);
for (let i = 0; i * steps_per_tick < 300; i++) {
simulation.tick(steps_per_tick);
circs.attr("cx", (c) => c.x).attr("cy", (c) => c.y);
yield svg.node();
}
}