@@ -357,6 +357,7 @@ def __init__(self, pixel_object, speed, color, period=5, max_intensity=1, min_in
357
357
self .max_intensity = max_intensity
358
358
self .min_intensity = min_intensity
359
359
self ._direction = 1.0
360
+ # TODO Fix this:
360
361
self ._intensity_step = 2 / (period / speed )
361
362
self ._bpp = len (pixel_object [0 ])
362
363
super (Pulse , self ).__init__ (pixel_object , speed , color )
@@ -374,6 +375,47 @@ def draw(self):
374
375
self .show ()
375
376
376
377
378
+ class Chase (Animation ):
379
+ """
380
+ Chase pixels in one direction single color.
381
+
382
+ :param pixel_object: The initialised LED object.
383
+ :param int speed: Animation speed rate in seconds, e.g. ``0.1``.
384
+ :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
385
+ :param size: Number of pixels per chase group.
386
+ :param reverse: Reverse direction.
387
+ """
388
+
389
+ # pylint: disable=too-many-arguments
390
+ def __init__ (self , pixel_object , speed , color , size = 3 , reverse = False ):
391
+ self ._size = size * 2
392
+ self ._direction = 1
393
+ self ._reverse = reverse
394
+ self ._n = 0
395
+ super (Chase , self ).__init__ (pixel_object , speed , color )
396
+
397
+ @property
398
+ def reverse (self ):
399
+ """
400
+ Whether the animation is reversed
401
+ """
402
+ return self ._reverse
403
+
404
+ @reverse .setter
405
+ def reverse (self , value ):
406
+ self ._reverse = value
407
+ self ._direction = - 1 if self ._reverse else 1
408
+
409
+ def draw (self ):
410
+ self ._n = (self ._n + 1 ) % self ._size
411
+ n = self ._n
412
+ size = self ._size
413
+ half_size = size // 2
414
+ for i in range (len (self .pixel_object )):
415
+ self .pixel_object [i ] = self .color if ((i + n ) % size ) < half_size else (0 , 0 , 0 )
416
+ self .show ()
417
+
418
+
377
419
class AnimationSequence :
378
420
"""
379
421
A sequence of Animations to run in sequence, looping forever.
0 commit comments