pylint fixes

This commit is contained in:
foamyguy 2024-10-31 15:28:02 -05:00
parent 5ca431625d
commit 4b223c310b
5 changed files with 30 additions and 11 deletions

View file

@ -7,7 +7,7 @@ Adapted From `adafruit_led_animation.animation.rainbow`
"""
from adafruit_led_animation.animation import Animation
from adafruit_led_animation.color import BLACK, colorwheel
from adafruit_led_animation.color import colorwheel
from adafruit_led_animation import MS_PER_SECOND, monotonic_ms
@ -30,7 +30,8 @@ class RainbowSweepAnimation(Animation):
DIRECTION_END_TO_START = 1
# pylint: disable=too-many-arguments
def __init__(
self, pixel_object, speed, color, sweep_speed=0.3, period=1, name=None, sweep_direction=DIRECTION_START_TO_END
self, pixel_object, speed, color, sweep_speed=0.3, period=1,
name=None, sweep_direction=DIRECTION_START_TO_END
):
super().__init__(pixel_object, speed, color, name=name)
self._period = period
@ -112,7 +113,8 @@ class RainbowSweepAnimation(Animation):
# if end to start direction
if self.direction == self.DIRECTION_END_TO_START:
# set the current pixels at the end of the strand to the specified color
self.pixel_object[self.sweep_index:] = [self.color] * (len(self.pixel_object) - self.sweep_index)
self.pixel_object[self.sweep_index:] = (
[self.color] * (len(self.pixel_object) - self.sweep_index))
# if start to end direction
elif self.direction == self.DIRECTION_START_TO_END:

View file

@ -4,11 +4,12 @@
"""
SnakeAnimation helper class
"""
import random
from micropython import const
from adafruit_led_animation.animation import Animation
from adafruit_led_animation.grid import PixelGrid, HORIZONTAL
import random
class SnakeAnimation(Animation):
@ -34,7 +35,8 @@ class SnakeAnimation(Animation):
self.snake_length = snake_length
# create a PixelGrid helper to access our strand as a 2D grid
self.pixel_grid = PixelGrid(pixel_object, width, height, orientation=HORIZONTAL, alternating=False)
self.pixel_grid = PixelGrid(pixel_object, width, height,
orientation=HORIZONTAL, alternating=False)
# size variables
self.width = width
@ -43,6 +45,8 @@ class SnakeAnimation(Animation):
# list that will hold locations of snake segments
self.snake_pixels = []
self.direction = None
# initialize the snake
self._new_snake()
@ -75,7 +79,8 @@ class SnakeAnimation(Animation):
returns true if the snake can move in the given direction
"""
# location of the next tile if we would move that direction
next_tile = tuple(map(sum, zip(SnakeAnimation.DIRECTION_OFFSETS[direction], self.snake_pixels[0])))
next_tile = tuple(map(sum, zip(
SnakeAnimation.DIRECTION_OFFSETS[direction], self.snake_pixels[0])))
# if the tile is one of the snake segments
if next_tile in self.snake_pixels:
@ -111,7 +116,8 @@ class SnakeAnimation(Animation):
# loop over the copied list of directions to check
while len(directions_to_check) > 0:
# choose a random one from the list and pop it out of the list
possible_direction = directions_to_check.pop(random.randint(0, len(directions_to_check)-1))
possible_direction = directions_to_check.pop(
random.randint(0, len(directions_to_check)-1))
# if we can move the chosen direction
if self._can_move(possible_direction):
# return the chosen direction
@ -140,7 +146,8 @@ class SnakeAnimation(Animation):
self.direction = self._choose_direction()
# the location of the next tile where the head of the snake will move to
next_tile = tuple(map(sum, zip(SnakeAnimation.DIRECTION_OFFSETS[self.direction], self.snake_pixels[0])))
next_tile = tuple(map(sum, zip(
SnakeAnimation.DIRECTION_OFFSETS[self.direction], self.snake_pixels[0])))
# insert the next tile at list index 0
self.snake_pixels.insert(0, next_tile)

View file

@ -32,6 +32,8 @@ class SweepAnimation(Animation):
# boolean indicating whether we're currently sweeping LEDs on or off
self.sweeping_on = True
self.cycle_complete = False
# This animation supports the cycle complete callback
on_cycle_complete_supported = True

View file

@ -21,4 +21,4 @@ zipper = ZipperAnimation(pixels, speed=0.1, color=PINK, alternate_color=JADE)
while True:
# call animation to show the next animation frame
zipper.animate()
zipper.animate()

View file

@ -9,7 +9,7 @@ from adafruit_led_animation.animation import Animation
class ZipperAnimation(Animation):
def __init__(self, pixel_object, speed, color):
def __init__(self, pixel_object, speed, color, alternate_color=None):
"""
Lights up every other LED from each ends of the strand, passing each
other in the middle and resulting in the full strand being lit at the
@ -23,6 +23,12 @@ class ZipperAnimation(Animation):
# Call super class initialization
super().__init__(pixel_object, speed, color)
# if alternate color is None then use single color
if alternate_color is None:
self.alternate_color = color
else:
self.alternate_color = alternate_color
# custom variable to store the current step of the animation
self.current_step = 0
@ -30,6 +36,8 @@ class ZipperAnimation(Animation):
# length in steps.
self.last_step = len(pixel_object) // 2
self.cycle_complete = False
# This animation supports the cycle complete callback
on_cycle_complete_supported = True
@ -46,7 +54,7 @@ class ZipperAnimation(Animation):
self.pixel_object[self.current_step * 2] = self.color
# Turn on 1 odd indexed pixel starting from the end of the strand
self.pixel_object[-(self.current_step * 2) - 1] = self.color
self.pixel_object[-(self.current_step * 2) - 1] = self.alternate_color
except IndexError:
pass