more pylint fixes
This commit is contained in:
parent
6cb551cbe0
commit
cf348e0156
1 changed files with 10 additions and 7 deletions
|
|
@ -10,6 +10,10 @@ from adafruit_led_animation.animation import Animation
|
||||||
from adafruit_led_animation.grid import PixelGrid, HORIZONTAL
|
from adafruit_led_animation.grid import PixelGrid, HORIZONTAL
|
||||||
|
|
||||||
|
|
||||||
|
def _is_pixel_off(pixel):
|
||||||
|
return pixel[0] == 0 and pixel[1] == 0 and pixel[2] == 0
|
||||||
|
|
||||||
|
|
||||||
class ConwaysLifeAnimation(Animation):
|
class ConwaysLifeAnimation(Animation):
|
||||||
# Constants
|
# Constants
|
||||||
DIRECTION_OFFSETS = [
|
DIRECTION_OFFSETS = [
|
||||||
|
|
@ -36,7 +40,8 @@ class ConwaysLifeAnimation(Animation):
|
||||||
equilibrium_restart=True,
|
equilibrium_restart=True,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Conway's Game of Life implementation. Watch the cells live and die based on the classic rules.
|
Conway's Game of Life implementation. Watch the cells
|
||||||
|
live and die based on the classic rules.
|
||||||
|
|
||||||
:param pixel_object: The initialised LED object.
|
:param pixel_object: The initialised LED object.
|
||||||
:param float speed: Animation refresh rate in seconds, e.g. ``0.1``.
|
:param float speed: Animation refresh rate in seconds, e.g. ``0.1``.
|
||||||
|
|
@ -71,9 +76,6 @@ class ConwaysLifeAnimation(Animation):
|
||||||
|
|
||||||
# self._init_cells()
|
# self._init_cells()
|
||||||
|
|
||||||
def _is_pixel_off(self, pixel):
|
|
||||||
return pixel[0] == 0 and pixel[1] == 0 and pixel[2] == 0
|
|
||||||
|
|
||||||
def _is_grid_empty(self):
|
def _is_grid_empty(self):
|
||||||
"""
|
"""
|
||||||
Checks if the grid is empty.
|
Checks if the grid is empty.
|
||||||
|
|
@ -82,7 +84,7 @@ class ConwaysLifeAnimation(Animation):
|
||||||
"""
|
"""
|
||||||
for y in range(self.height):
|
for y in range(self.height):
|
||||||
for x in range(self.width):
|
for x in range(self.width):
|
||||||
if not self._is_pixel_off(self.pixel_grid[x, y]):
|
if not _is_pixel_off(self.pixel_grid[x, y]):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
@ -106,7 +108,7 @@ class ConwaysLifeAnimation(Animation):
|
||||||
neighbors = 0
|
neighbors = 0
|
||||||
for direction in ConwaysLifeAnimation.DIRECTION_OFFSETS:
|
for direction in ConwaysLifeAnimation.DIRECTION_OFFSETS:
|
||||||
try:
|
try:
|
||||||
if not self._is_pixel_off(
|
if not _is_pixel_off(
|
||||||
self.pixel_grid[cell[0] + direction[0], cell[1] + direction[1]]
|
self.pixel_grid[cell[0] + direction[0], cell[1] + direction[1]]
|
||||||
):
|
):
|
||||||
neighbors += 1
|
neighbors += 1
|
||||||
|
|
@ -115,6 +117,7 @@ class ConwaysLifeAnimation(Animation):
|
||||||
return neighbors
|
return neighbors
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
"""
|
"""
|
||||||
draw the current frame of the animation
|
draw the current frame of the animation
|
||||||
|
|
||||||
|
|
@ -137,7 +140,7 @@ class ConwaysLifeAnimation(Animation):
|
||||||
for x in range(self.width):
|
for x in range(self.width):
|
||||||
|
|
||||||
# check and set the current cell type, live or dead
|
# check and set the current cell type, live or dead
|
||||||
if self._is_pixel_off(self.pixel_grid[x, y]):
|
if _is_pixel_off(self.pixel_grid[x, y]):
|
||||||
cur_cell_type = ConwaysLifeAnimation.DEAD
|
cur_cell_type = ConwaysLifeAnimation.DEAD
|
||||||
else:
|
else:
|
||||||
cur_cell_type = ConwaysLifeAnimation.LIVE
|
cur_cell_type = ConwaysLifeAnimation.LIVE
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue