10
10
from adafruit_led_animation .grid import PixelGrid , HORIZONTAL
11
11
12
12
13
+ def _is_pixel_off (pixel ):
14
+ return pixel [0 ] == 0 and pixel [1 ] == 0 and pixel [2 ] == 0
15
+
16
+
13
17
class ConwaysLifeAnimation (Animation ):
14
18
# Constants
15
19
DIRECTION_OFFSETS = [
@@ -36,7 +40,8 @@ def __init__(
36
40
equilibrium_restart = True ,
37
41
):
38
42
"""
39
- Conway's Game of Life implementation. Watch the cells live and die based on the classic rules.
43
+ Conway's Game of Life implementation. Watch the cells
44
+ live and die based on the classic rules.
40
45
41
46
:param pixel_object: The initialised LED object.
42
47
:param float speed: Animation refresh rate in seconds, e.g. ``0.1``.
@@ -71,9 +76,6 @@ def __init__(
71
76
72
77
# self._init_cells()
73
78
74
- def _is_pixel_off (self , pixel ):
75
- return pixel [0 ] == 0 and pixel [1 ] == 0 and pixel [2 ] == 0
76
-
77
79
def _is_grid_empty (self ):
78
80
"""
79
81
Checks if the grid is empty.
@@ -82,7 +84,7 @@ def _is_grid_empty(self):
82
84
"""
83
85
for y in range (self .height ):
84
86
for x in range (self .width ):
85
- if not self . _is_pixel_off (self .pixel_grid [x , y ]):
87
+ if not _is_pixel_off (self .pixel_grid [x , y ]):
86
88
return False
87
89
88
90
return True
@@ -106,7 +108,7 @@ def _count_neighbors(self, cell):
106
108
neighbors = 0
107
109
for direction in ConwaysLifeAnimation .DIRECTION_OFFSETS :
108
110
try :
109
- if not self . _is_pixel_off (
111
+ if not _is_pixel_off (
110
112
self .pixel_grid [cell [0 ] + direction [0 ], cell [1 ] + direction [1 ]]
111
113
):
112
114
neighbors += 1
@@ -115,6 +117,7 @@ def _count_neighbors(self, cell):
115
117
return neighbors
116
118
117
119
def draw (self ):
120
+ # pylint: disable=too-many-branches
118
121
"""
119
122
draw the current frame of the animation
120
123
@@ -137,7 +140,7 @@ def draw(self):
137
140
for x in range (self .width ):
138
141
139
142
# check and set the current cell type, live or dead
140
- if self . _is_pixel_off (self .pixel_grid [x , y ]):
143
+ if _is_pixel_off (self .pixel_grid [x , y ]):
141
144
cur_cell_type = ConwaysLifeAnimation .DEAD
142
145
else :
143
146
cur_cell_type = ConwaysLifeAnimation .LIVE
0 commit comments