{
let ghosts = [];
const svg = d3.create("svg")
.attr("viewbox", [0, 0, WIDTH, HEIGHT])
.style("width", `${WIDTH}px`)
.style("height", `${HEIGHT}px`)
.style("background", "#222");
while (toggle){
ghosts = retire(ghosts);
ghosts.forEach(walk);
if (ghosts.length <2 || randint(0, 3) < 1){
const newGhost = makeGhost(ghosts);
ghosts.forEach((g)=> runaway(g, newGhost));
ghosts.push(newGhost);
}
animate(svg, ghosts);
yield svg.node();
await Promises.tick(1000);
}
return svg.node()
}