88
99from adafruit_led_animation .animation import Animation
1010from adafruit_led_animation .grid import PixelGrid , HORIZONTAL
11- import random
1211
1312
1413class ConwaysLifeAnimation (Animation ):
@@ -21,12 +20,21 @@ class ConwaysLifeAnimation(Animation):
2120 (1 , 1 ),
2221 (- 1 , 1 ),
2322 (1 , - 1 ),
24- (- 1 , - 1 )
23+ (- 1 , - 1 ),
2524 ]
2625 LIVE = const (0x01 )
2726 DEAD = const (0x00 )
2827
29- def __init__ (self , pixel_object , speed , color , width , height , initial_cells , equilibrium_restart = True ):
28+ def __init__ (
29+ self ,
30+ pixel_object ,
31+ speed ,
32+ color ,
33+ width ,
34+ height ,
35+ initial_cells ,
36+ equilibrium_restart = True ,
37+ ):
3038 """
3139 Conway's Game of Life implementation. Watch the cells live and die based on the classic rules.
3240
@@ -47,7 +55,9 @@ def __init__(self, pixel_object, speed, color, width, height, initial_cells, equ
4755 self .initial_cells = initial_cells
4856
4957 # PixelGrid helper to access the strand as a 2D grid
50- self .pixel_grid = PixelGrid (pixel_object , width , height , orientation = HORIZONTAL , alternating = False )
58+ self .pixel_grid = PixelGrid (
59+ pixel_object , width , height , orientation = HORIZONTAL , alternating = False
60+ )
5161
5262 # size of the grid
5363 self .width = width
@@ -59,7 +69,7 @@ def __init__(self, pixel_object, speed, color, width, height, initial_cells, equ
5969 # counter to store how many turns since the last change
6070 self .equilibrium_turns = 0
6171
62- #self._init_cells()
72+ # self._init_cells()
6373
6474 def _is_pixel_off (self , pixel ):
6575 return pixel [0 ] == 0 and pixel [1 ] == 0 and pixel [2 ] == 0
@@ -72,7 +82,7 @@ def _is_grid_empty(self):
7282 """
7383 for y in range (self .height ):
7484 for x in range (self .width ):
75- if not self ._is_pixel_off (self .pixel_grid [x ,y ]):
85+ if not self ._is_pixel_off (self .pixel_grid [x , y ]):
7686 return False
7787
7888 return True
@@ -96,7 +106,9 @@ def _count_neighbors(self, cell):
96106 neighbors = 0
97107 for direction in ConwaysLifeAnimation .DIRECTION_OFFSETS :
98108 try :
99- if not self ._is_pixel_off (self .pixel_grid [cell [0 ] + direction [0 ], cell [1 ] + direction [1 ]]):
109+ if not self ._is_pixel_off (
110+ self .pixel_grid [cell [0 ] + direction [0 ], cell [1 ] + direction [1 ]]
111+ ):
100112 neighbors += 1
101113 except IndexError :
102114 pass
@@ -125,7 +137,7 @@ def draw(self):
125137 for x in range (self .width ):
126138
127139 # check and set the current cell type, live or dead
128- if self ._is_pixel_off (self .pixel_grid [x ,y ]):
140+ if self ._is_pixel_off (self .pixel_grid [x , y ]):
129141 cur_cell_type = ConwaysLifeAnimation .DEAD
130142 else :
131143 cur_cell_type = ConwaysLifeAnimation .LIVE
0 commit comments