@@ -60,6 +60,7 @@ class Comet(Animation):
60
60
maximum of the length of the ``pixel_object``.
61
61
:param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
62
62
:param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
63
+ :param bool ring: Ring mode. Defaults to ``False``.
63
64
"""
64
65
65
66
# pylint: disable=too-many-arguments,too-many-instance-attributes
@@ -72,9 +73,12 @@ def __init__(
72
73
reverse = False ,
73
74
bounce = False ,
74
75
name = None ,
76
+ ring = False ,
75
77
):
76
78
if tail_length == 0 :
77
79
tail_length = len (pixel_object ) // 4
80
+ if bounce and ring :
81
+ raise ValueError ("Cannot combine bounce and ring mode" )
78
82
self .reverse = reverse
79
83
self .bounce = bounce
80
84
self ._initial_reverse = reverse
@@ -87,6 +91,9 @@ def __init__(
87
91
self ._left_side = - self ._tail_length
88
92
self ._right_side = self ._num_pixels
89
93
self ._tail_start = 0
94
+ self ._ring = ring
95
+ if ring :
96
+ self ._left_side = 0
90
97
self .reset ()
91
98
super ().__init__ (pixel_object , speed , color , name = name )
92
99
@@ -107,7 +114,10 @@ def draw(self):
107
114
for pixel_no , color in enumerate (colors ):
108
115
draw_at = self ._tail_start + pixel_no
109
116
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
+
111
121
self .pixel_object [draw_at ] = color
112
122
113
123
self ._tail_start += self ._direction
@@ -116,6 +126,8 @@ def draw(self):
116
126
if self .bounce :
117
127
self .reverse = not self .reverse
118
128
self ._direction = - self ._direction
129
+ elif self ._ring :
130
+ self ._tail_start = self ._tail_start % self ._num_pixels
119
131
else :
120
132
self .reset ()
121
133
if self .reverse == self ._initial_reverse and self .draw_count > 0 :
@@ -130,3 +142,6 @@ def reset(self):
130
142
self ._tail_start = self ._num_pixels + self ._tail_length + 1
131
143
else :
132
144
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