16
16
# machine.freq(250_000_000)
17
17
18
18
INITIAL_LIFE = 128 # Number of live cells to seed
19
- GENERATION_TIME_MS = 50 # MS between generations
20
- MINIMUM_LIFE = 15 # Auto reseed when only this many alive cells remain
19
+ GENERATION_TIME_MS = 100 # MS between generations
21
20
SMOOTHED = True # Enable for a more organic if somewhat unsettling feel
21
+ STALEMATE_DEPTH = 5 # How many generations of changes must match before reset
22
22
23
23
DECAY = 0.90 # Rate at which smoothing effect decays, higher number = more persistent, 1.0 = no decay
24
24
TENACITY = 32 # Rate at which smoothing effect increases
27
27
su .set_brightness (0.5 )
28
28
graphics = PicoGraphics (DISPLAY_STELLAR_UNICORN , pen_type = PEN_P8 )
29
29
30
+ changed_cells = []
31
+
32
+
30
33
for c in range (256 ):
31
34
graphics .create_pen (c // 2 , 0 , c )
32
35
33
36
34
37
def update ():
35
- global last_gen
38
+ global last_gen , changed_cells
36
39
37
40
if SMOOTHED :
38
41
duration [:] += life * TENACITY
@@ -43,10 +46,6 @@ def update():
43
46
44
47
last_gen = time .ticks_ms ()
45
48
46
- if numpy .sum (life ) < MINIMUM_LIFE :
47
- seed_life ()
48
- return
49
-
50
49
# Rollin' rollin' rollin.
51
50
_N = numpy .roll (life , - 1 , axis = 0 )
52
51
_NW = numpy .roll (_N , - 1 , axis = 1 )
@@ -71,7 +70,15 @@ def update():
71
70
# Any alive cells with more than three neighbours should die
72
71
next_generation [:] -= (neighbours [:] > 3 ) * life
73
72
74
- life [:] = numpy .clip (next_generation , 0 , 1 )
73
+ next_generation [:] = numpy .clip (next_generation , 0 , 1 )
74
+
75
+ changed_cells .append (numpy .sum (life != next_generation ))
76
+ changed_cells = changed_cells [- STALEMATE_DEPTH :]
77
+
78
+ life [:] = next_generation
79
+
80
+ if changed_cells .count (changed_cells [0 ]) == STALEMATE_DEPTH :
81
+ seed_life (INITIAL_LIFE // 2 )
75
82
76
83
77
84
def draw ():
@@ -83,8 +90,8 @@ def draw():
83
90
su .update (graphics )
84
91
85
92
86
- def seed_life ():
87
- for _ in range (INITIAL_LIFE ):
93
+ def seed_life (amount = INITIAL_LIFE ):
94
+ for _ in range (amount ):
88
95
x = random .randint (0 , width - 1 )
89
96
y = random .randint (0 , height - 1 )
90
97
life [y ][x ] = int (True ) # Avoid: TypeError: 'bool' object isn't iterable
0 commit comments