4848
4949from . import NANOS_PER_SECOND
5050from .color import BLACK , RAINBOW
51+
5152try :
5253 from time import monotonic_ns
5354except ImportError :
@@ -68,6 +69,7 @@ class Animation:
6869 """
6970 Base class for animations.
7071 """
72+
7173 # pylint: disable=too-many-arguments
7274 def __init__ (self , pixel_object , speed , color , peers = None , paused = False ):
7375 self .pixel_object = pixel_object
@@ -152,7 +154,7 @@ def color(self, color):
152154 if self ._color == color :
153155 return
154156 if isinstance (color , int ):
155- color = (color >> 16 & 0xff , color >> 8 & 0xff , color & 0xff )
157+ color = (color >> 16 & 0xFF , color >> 8 & 0xFF , color & 0xFF )
156158 self ._color = color
157159 self ._recompute_color (color )
158160
@@ -183,6 +185,7 @@ class ColorCycle(Animation):
183185 :param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex
184186 format. Defaults to a rainbow color cycle.
185187 """
188+
186189 def __init__ (self , pixel_object , speed , colors = RAINBOW ):
187190 self .colors = colors
188191 super (ColorCycle , self ).__init__ (pixel_object , speed , colors [0 ])
@@ -209,6 +212,7 @@ class Blink(ColorCycle):
209212 :param int speed: Animation speed in seconds, e.g. ``0.1``.
210213 :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
211214 """
215+
212216 def __init__ (self , pixel_object , speed , color ):
213217 super (Blink , self ).__init__ (pixel_object , speed , [color , BLACK ])
214218
@@ -223,6 +227,7 @@ class Solid(ColorCycle):
223227 :param pixel_object: The initialised LED object.
224228 :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
225229 """
230+
226231 def __init__ (self , pixel_object , color ):
227232 super (Solid , self ).__init__ (pixel_object , speed = 1 , colors = [color ])
228233
@@ -243,8 +248,11 @@ class Comet(Animation):
243248 :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
244249 :param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
245250 """
251+
246252 # pylint: disable=too-many-arguments
247- def __init__ (self , pixel_object , speed , color , tail_length = 10 , reverse = False , bounce = False ):
253+ def __init__ (
254+ self , pixel_object , speed , color , tail_length = 10 , reverse = False , bounce = False
255+ ):
248256 self ._tail_length = tail_length + 1
249257 self ._color_step = 0.9 / tail_length
250258 self ._color_offset = 0.1
@@ -260,9 +268,11 @@ def __init__(self, pixel_object, speed, color, tail_length=10, reverse=False, bo
260268
261269 def _recompute_color (self , color ):
262270 self ._comet_colors = [BLACK ] + [
263- [int (color [rgb ] * ((n * self ._color_step ) + self ._color_offset ))
264- for rgb in range (len (color ))
265- ] for n in range (self ._tail_length - 1 )
271+ [
272+ int (color [rgb ] * ((n * self ._color_step ) + self ._color_offset ))
273+ for rgb in range (len (color ))
274+ ]
275+ for n in range (self ._tail_length - 1 )
266276 ]
267277 self ._reverse_comet_colors = list (reversed (self ._comet_colors ))
268278
@@ -283,9 +293,11 @@ def _comet_generator(self):
283293 end = num_pixels - start
284294 if start <= 0 :
285295 num_visible = self ._tail_length + start
286- self .pixel_object [0 :num_visible ] = colors [self ._tail_length - num_visible :]
296+ self .pixel_object [0 :num_visible ] = colors [
297+ self ._tail_length - num_visible :
298+ ]
287299 else :
288- self .pixel_object [start : start + end ] = colors [0 :end ]
300+ self .pixel_object [start : start + end ] = colors [0 :end ]
289301 self .show ()
290302 yield
291303 if self .bounce :
@@ -303,6 +315,7 @@ class Sparkle(Animation):
303315 :param int speed: Animation speed in seconds, e.g. ``0.1``.
304316 :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
305317 """
318+
306319 def __init__ (self , pixel_object , speed , color ):
307320 if len (pixel_object ) < 2 :
308321 raise ValueError ("Sparkle needs at least 2 pixels" )
@@ -343,7 +356,9 @@ class Pulse(Animation):
343356 """
344357
345358 # pylint: disable=too-many-arguments
346- def __init__ (self , pixel_object , speed , color , period = 5 , max_intensity = 1 , min_intensity = 0 ):
359+ def __init__ (
360+ self , pixel_object , speed , color , period = 5 , max_intensity = 1 , min_intensity = 0
361+ ):
347362 self .max_intensity = max_intensity
348363 self .min_intensity = min_intensity
349364 self ._period = period
@@ -359,10 +374,14 @@ def draw(self):
359374 now = monotonic_ns ()
360375 time_since_last_draw = (now - self ._last_update ) / NANOS_PER_SECOND
361376 self ._last_update = now
362- pos = self ._cycle_position = (self ._cycle_position + time_since_last_draw ) % self ._period
377+ pos = self ._cycle_position = (
378+ self ._cycle_position + time_since_last_draw
379+ ) % self ._period
363380 if pos > self ._half_period :
364381 pos = self ._period - pos
365- intensity = self .min_intensity + (pos * self ._intensity_delta * self ._position_factor )
382+ intensity = self .min_intensity + (
383+ pos * self ._intensity_delta * self ._position_factor
384+ )
366385 color = [int (self .color [n ] * intensity ) for n in range (self ._bpp )]
367386 self .fill (color )
368387 self .show ()
@@ -408,8 +427,10 @@ def draw(self):
408427 self .pixel_object .fill ((0 , 0 , 0 ))
409428 for i in range (self ._size ):
410429 n = (self ._n + i ) % self ._repeat_width
411- num = len (self .pixel_object [n ::self ._repeat_width ])
412- self .pixel_object [n ::self ._repeat_width ] = [self .group_color (n ) for n in range (num )]
430+ num = len (self .pixel_object [n :: self ._repeat_width ])
431+ self .pixel_object [n :: self ._repeat_width ] = [
432+ self .group_color (n ) for n in range (num )
433+ ]
413434 self ._n = (self ._n + self ._direction ) % self ._repeat_width
414435 self .show ()
415436
@@ -449,9 +470,12 @@ class AnimationSequence:
449470 while True:
450471 animations.animate()
451472 """
473+
452474 def __init__ (self , * members , advance_interval = None , auto_clear = False ):
453475 self ._members = members
454- self ._advance_interval = advance_interval * NANOS_PER_SECOND if advance_interval else None
476+ self ._advance_interval = (
477+ advance_interval * NANOS_PER_SECOND if advance_interval else None
478+ )
455479 self ._last_advance = monotonic_ns ()
456480 self ._current = 0
457481 self ._auto_clear = auto_clear
@@ -545,6 +569,7 @@ class AnimationGroup:
545569 first member of the group. Defaults to ``False``.
546570
547571 """
572+
548573 def __init__ (self , * members , sync = False ):
549574 self ._members = members
550575 self ._sync = sync
@@ -584,16 +609,16 @@ def fill(self, color):
584609 """
585610 Fills all pixel objects in the group with a color.
586611 """
587- self ._for_all (' fill' , color )
612+ self ._for_all (" fill" , color )
588613
589614 def freeze (self ):
590615 """
591616 Freeze all animations in the group.
592617 """
593- self ._for_all (' freeze' )
618+ self ._for_all (" freeze" )
594619
595620 def resume (self ):
596621 """
597622 Resume all animations in the group.
598623 """
599- self ._for_all (' resume' )
624+ self ._for_all (" resume" )
0 commit comments