wolframAutomata = {
const ruleset = ruleNumberToRuleset(ruleNumber);
const cells = [initialCells];
let nextGenerationCells = initialCells;
for (let i = 1; i < numCells; i++) {
const generation = i;
nextGenerationCells = generate(generation, nextGenerationCells, ruleset);
cells.push(nextGenerationCells);
}
const [onRects, offRects] = cells.reduce((genAcc, generation, genI) => {
const [genOnCells, genOffCells] = generation.reduce((cellAcc, cell, i) => {
const isFilled = cell === 1;
const fill = isFilled ? '#000000' : '#ffffff';
const node = svg`
<rect
x=${i * cellSize}
y=${genI * cellSize}
width=${cellSize}
height=${cellSize}
fill=${fill}
stroke="#000000"
stroke-width="0.25"
>
`;
if (isFilled) {
cellAcc[0].push(node);
} else {
cellAcc[1].push(node);
}
return cellAcc;
}, [[], []]);
genAcc[0].push(genOnCells);
genAcc[1].push(genOffCells);
return genAcc;
}, [[], []]);
return svg`
<svg
viewBox="0 0 ${width} ${height}"
width=${width}
height=${height}
stroke="#000000"
stroke-width="0.25"
>
<g id="off">${offRects.flat()}</g>
<g id="on">${onRects.flat()}</g>
</svg>
`
}