@@ -60,6 +60,7 @@ class Comet(Animation):
6060 maximum of the length of the ``pixel_object``.
6161 :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
6262 :param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
63+ :param bool ring: Ring mode. Defaults to ``False``.
6364 """
6465
6566 # pylint: disable=too-many-arguments,too-many-instance-attributes
@@ -72,9 +73,12 @@ def __init__(
7273 reverse = False ,
7374 bounce = False ,
7475 name = None ,
76+ ring = False ,
7577 ):
7678 if tail_length == 0 :
7779 tail_length = len (pixel_object ) // 4
80+ if bounce and ring :
81+ raise ValueError ("Cannot combine bounce and ring mode" )
7882 self .reverse = reverse
7983 self .bounce = bounce
8084 self ._initial_reverse = reverse
@@ -87,6 +91,9 @@ def __init__(
8791 self ._left_side = - self ._tail_length
8892 self ._right_side = self ._num_pixels
8993 self ._tail_start = 0
94+ self ._ring = ring
95+ if ring :
96+ self ._left_side = 0
9097 self .reset ()
9198 super ().__init__ (pixel_object , speed , color , name = name )
9299
@@ -107,7 +114,10 @@ def draw(self):
107114 for pixel_no , color in enumerate (colors ):
108115 draw_at = self ._tail_start + pixel_no
109116 if draw_at < 0 or draw_at >= self ._num_pixels :
110- continue
117+ if not self ._ring :
118+ continue
119+ draw_at = draw_at % self ._num_pixels
120+
111121 self .pixel_object [draw_at ] = color
112122
113123 self ._tail_start += self ._direction
@@ -116,6 +126,8 @@ def draw(self):
116126 if self .bounce :
117127 self .reverse = not self .reverse
118128 self ._direction = - self ._direction
129+ elif self ._ring :
130+ self ._tail_start = self ._tail_start % self ._num_pixels
119131 else :
120132 self .reset ()
121133 if self .reverse == self ._initial_reverse and self .draw_count > 0 :
@@ -130,3 +142,6 @@ def reset(self):
130142 self ._tail_start = self ._num_pixels + self ._tail_length + 1
131143 else :
132144 self ._tail_start = - self ._tail_length - 1
145+
146+ if self ._ring :
147+ self ._tail_start = self ._tail_start % self ._num_pixels
0 commit comments