Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
* [Langtons Ant](cellular_automata/langtons_ant.py)
* [Nagel Schrekenberg](cellular_automata/nagel_schrekenberg.py)
* [One Dimensional](cellular_automata/one_dimensional.py)
* [Von Neumann](cellular_automata/von_neumann.py)
* [Wa Tor](cellular_automata/wa_tor.py)

## Ciphers
Expand Down
18 changes: 18 additions & 0 deletions cellular_automata/von_neumann.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,25 @@ def simulate_von_neumann_cellular_automaton(
return generation_history


def visualise_simulation_history(generation_history: list[np.ndarray]) -> None:
# Imports within the function as not required for the simulation algorithm.
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()

def animate_func(i):
ax.imshow(generation_history[i])

anim = FuncAnimation(fig, animate_func, frames=len(generation_history)) # noqa: F841

plt.show()


if __name__ == "__main__":
import doctest

doctest.testmod(verbose=True)

history = simulate_von_neumann_cellular_automaton()
visualise_simulation_history(history)