display1 = {
const space = spacetime[step % spacetime.length];
const forces = calcForces(space);
const viewBox = [-15, -15, 30, 30];
const svg = d3
.create("svg")
.style("border", "1px solid")
.style("height", "600px")
.attr("viewBox", viewBox);
const defs = svg.append("svg:defs");
for (const color of colorMap) {
addArrowMarker(defs, "arrow_" + color.substr(1), color);
}
const g = svg.append("g");
g.append("g")
.selectAll("circle")
.data(hexagonDots(viewBox[2]))
.join("circle")
.attr("cx", (qr) => hec.axialToFlatCart(qr)[0])
.attr("cy", (qr) => hec.axialToFlatCart(qr)[1])
.attr("r", 0.05);
g.append("g")
.selectAll("circle")
.data(space)
.join("circle")
.attr("cx", ({ pos }) => hec.axialToFlatCart(pos)[0])
.attr("cy", ({ pos }) => hec.axialToFlatCart(pos)[1])
.attr("fill", ({ kind }) => colorMap[kind])
.attr("r", 0.5);
g.append("g")
.selectAll("path")
.data(forces.filter(({ vec }) => vec3.len(vec) > 0))
.join("path")
.attr("stroke", (f) => colorMap[f.target.kind])
.attr("stroke-width", 0.1)
.attr("d", (force) =>
d3.line()([
hec.axialToFlatCart(force.target.pos),
hec.axialToFlatCart(vec3.add([], force.target.pos, force.vec))
])
)
.attr(
"marker-end",
(f) => `url(#arrow_${colorMap[f.target.kind].substr(1)})`
);
svg.call(
d3.zoom().on("zoom", ({ transform }) => g.attr("transform", transform))
);
return svg.node();
}