14
14
Requirements: numpy, matplotlib
15
15
"""
16
16
17
- import sys
18
17
import doctest
18
+ import sys
19
19
20
20
import matplotlib .pyplot as plt
21
21
from matplotlib import animation
@@ -407,7 +407,23 @@ def visualize_cellular_automaton(
407
407
cbar .set_ticklabels (["Dead" ] + [f"Age { i } " for i in range (1 , max_age + 1 )])
408
408
409
409
# 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
+ """
411
427
im .set_array (generation_history [frame ])
412
428
ax .set_title (f"{ title } - Generation { frame } " , fontsize = 16 , pad = 20 )
413
429
return [im ]
@@ -576,7 +592,15 @@ def run_interactive_simulation(
576
592
577
593
578
594
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
+ """
580
604
try :
581
605
visualize_cellular_automaton (
582
606
rule_b = [3 ],
@@ -590,7 +614,15 @@ def demo_game_of_life() -> None:
590
614
591
615
592
616
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
+ """
594
626
try :
595
627
visualize_cellular_automaton (
596
628
rule_b = [3 , 6 ],
@@ -604,7 +636,15 @@ def demo_highlife() -> None:
604
636
605
637
606
638
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
+ """
608
648
try :
609
649
initial_state = np .zeros ((10 , 10 ), dtype = int )
610
650
initial_state [4 :7 , 5 ] = 1 # vertical line
@@ -620,7 +660,15 @@ def demo_oscillator() -> None:
620
660
621
661
622
662
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
+ """
624
672
try :
625
673
visualize_cellular_automaton (
626
674
rule_b = [2 ],
@@ -634,7 +682,15 @@ def demo_randomized() -> None:
634
682
635
683
636
684
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
+ """
638
694
try :
639
695
final_state = visualize_cellular_automaton (
640
696
rule_b = [3 ],
@@ -662,7 +718,15 @@ def demo_statistics() -> None:
662
718
663
719
664
720
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
+ """
666
730
print ("=" * 80 )
667
731
print ("VON NEUMANN CELLULAR AUTOMATON - FEATURE DEMONSTRATION" )
668
732
print ("=" * 80 )
0 commit comments