Skip to content

Commit 8fa6abc

Browse files
committed
improved doc strings
1 parent b27e02c commit 8fa6abc

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

cellular_automata/von_neumann.py

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
Requirements: numpy, matplotlib
1515
"""
1616

17-
import sys
1817
import doctest
18+
import sys
1919

2020
import matplotlib.pyplot as plt
2121
from matplotlib import animation
@@ -407,7 +407,23 @@ def visualize_cellular_automaton(
407407
cbar.set_ticklabels(["Dead"] + [f"Age {i}" for i in range(1, max_age + 1)])
408408

409409
# Animation function
410-
def animate(frame):
410+
def animate(frame: int) -> None:
411+
"""
412+
Animation update function for matplotlib FuncAnimation.
413+
414+
Parameters
415+
----------
416+
frame : int
417+
The current frame index.
418+
419+
Returns
420+
-------
421+
None
422+
423+
Examples
424+
--------
425+
>>> animate(0) # doctest: +SKIP
426+
"""
411427
im.set_array(generation_history[frame])
412428
ax.set_title(f"{title} - Generation {frame}", fontsize=16, pad=20)
413429
return [im]
@@ -576,7 +592,15 @@ def run_interactive_simulation(
576592

577593

578594
def demo_game_of_life() -> None:
579-
"""Example 1: Conway's Game of Life (B3/S23)."""
595+
"""
596+
Demonstrate Conway's Game of Life cellular automaton.
597+
598+
This will open a matplotlib animation window.
599+
600+
Examples
601+
--------
602+
>>> demo_game_of_life() # doctest: +SKIP
603+
"""
580604
try:
581605
visualize_cellular_automaton(
582606
rule_b=[3],
@@ -590,7 +614,15 @@ def demo_game_of_life() -> None:
590614

591615

592616
def demo_highlife() -> None:
593-
"""Example 2: HighLife (B36/S23)."""
617+
"""
618+
Demonstrate the HighLife cellular automaton (B36/S23).
619+
620+
This will open a matplotlib animation window.
621+
622+
Examples
623+
--------
624+
>>> demo_highlife() # doctest: +SKIP
625+
"""
594626
try:
595627
visualize_cellular_automaton(
596628
rule_b=[3, 6],
@@ -604,7 +636,15 @@ def demo_highlife() -> None:
604636

605637

606638
def demo_oscillator() -> None:
607-
"""Example 3: Oscillator (blinker)."""
639+
"""
640+
Demonstrate a simple oscillator pattern.
641+
642+
This will open a matplotlib animation window.
643+
644+
Examples
645+
--------
646+
>>> demo_oscillator() # doctest: +SKIP
647+
"""
608648
try:
609649
initial_state = np.zeros((10, 10), dtype=int)
610650
initial_state[4:7, 5] = 1 # vertical line
@@ -620,7 +660,15 @@ def demo_oscillator() -> None:
620660

621661

622662
def demo_randomized() -> None:
623-
"""Example 4: Randomized automaton (B2/S23)."""
663+
"""
664+
Demonstrate a cellular automaton with randomized initial state.
665+
666+
This will open a matplotlib animation window.
667+
668+
Examples
669+
--------
670+
>>> demo_randomized() # doctest: +SKIP
671+
"""
624672
try:
625673
visualize_cellular_automaton(
626674
rule_b=[2],
@@ -634,7 +682,15 @@ def demo_randomized() -> None:
634682

635683

636684
def demo_statistics() -> None:
637-
"""Example 5: Print statistics about automaton evolution."""
685+
"""
686+
Demonstrate cellular automaton population statistics.
687+
688+
Prints population and density statistics to the console.
689+
690+
Examples
691+
--------
692+
>>> demo_statistics() # doctest: +SKIP
693+
"""
638694
try:
639695
final_state = visualize_cellular_automaton(
640696
rule_b=[3],
@@ -662,7 +718,15 @@ def demo_statistics() -> None:
662718

663719

664720
def demonstrate_cellular_automaton_features() -> None:
665-
"""Runs a set of cellular automaton demonstrations."""
721+
"""
722+
Run all demonstration functions sequentially.
723+
724+
This will open multiple matplotlib animation windows and print statistics.
725+
726+
Examples
727+
--------
728+
>>> demonstrate_cellular_automaton_features() # doctest: +SKIP
729+
"""
666730
print("=" * 80)
667731
print("VON NEUMANN CELLULAR AUTOMATON - FEATURE DEMONSTRATION")
668732
print("=" * 80)

0 commit comments

Comments
 (0)