{
let svg = d3.create("svg").attr("viewBox", `0 0 ${columns} ${rows}`);
for (let i = 0; i < rows * columns; i++) {
let cell = simulation[i];
if (cell.alive) {
svg
.append("rect")
.attr("width", 1)
.attr("height", 1)
.attr("x", cell.column)
.attr("y", cell.row)
.attr("fill", !cell.history && cell.alive ? birthColor : aliveColor)
.transition()
.duration(delay)
.attr("fill", aliveColor);
} else {
svg
.append("rect")
.attr("width", 1)
.attr("height", 1)
.attr("x", cell.column)
.attr("y", cell.row)
.attr("fill", cell.history && !cell.alive ? dyingColor : deadColor)
.on("click", (e) => {
const [x, y] = d3.pointer(e);
simulation[Math.floor(y) * columns + Math.floor(x)].alive = 1;
})
.transition()
.duration(delay)
.attr("fill", deadColor);
}
}
return svg.node();
}