@@ -80,28 +80,133 @@ def __init__(
80
80
** kwargs ,
81
81
) -> None :
82
82
super ().__init__ (* args , ** kwargs )
83
+
83
84
# shift direction by angle/2
84
- direction = direction - angle / 2
85
+ self ._direction = direction - angle / 2
86
+ self ._radius = radius
87
+ self ._angle = angle
88
+ self ._segments = segments
89
+ self ._outline = outline
90
+ self ._fill = fill
91
+ self ._arc_width = arc_width
92
+ self .palette = None
93
+ self .vector_polygon = None
94
+ self .outline_polygon = None
95
+
96
+ self ._init_arc ()
97
+
98
+ def _init_arc (self ):
85
99
# create outer points
86
100
points = []
87
- for i in range (segments + 1 ):
88
- alpha = (i * angle / segments + direction ) / 180 * math .pi
89
- x0 = int (radius * math .cos (alpha ))
90
- y0 = - int (radius * math .sin (alpha ))
101
+ for i in range (self . _segments + 1 ):
102
+ alpha = (i * self . _angle / self . _segments + self . _direction ) / 180 * math .pi
103
+ x0 = int (self . _radius * math .cos (alpha ))
104
+ y0 = - int (self . _radius * math .sin (alpha ))
91
105
points .append ((x0 , y0 ))
92
106
93
107
# create inner points
94
- if arc_width > 1 :
95
- for i in range (segments , - 1 , - 1 ):
96
- alpha = (i * angle / segments + direction ) / 180 * math .pi
97
- x0 = int ((radius - arc_width ) * math .cos (alpha ))
98
- y0 = - int ((radius - arc_width ) * math .sin (alpha ))
108
+ if self ._arc_width > 1 :
109
+ for i in range (self ._segments , - 1 , - 1 ):
110
+ alpha = (
111
+ (i * self ._angle / self ._segments + self ._direction ) / 180 * math .pi
112
+ )
113
+ x0 = int ((self ._radius - self ._arc_width ) * math .cos (alpha ))
114
+ y0 = - int ((self ._radius - self ._arc_width ) * math .sin (alpha ))
99
115
points .append ((x0 , y0 ))
100
116
101
117
# create polygon(s) and add to ourselves
102
- if arc_width > 1 and HAVE_VECTORIO and fill is not None :
103
- palette = displayio .Palette (1 )
104
- palette [0 ] = fill
105
- self .append (vectorio .Polygon (pixel_shader = palette , points = points , x = 0 , y = 0 ))
106
- if outline is not None :
107
- self .append (Polygon (points , outline = outline , colors = 1 , close = arc_width > 1 ))
118
+ if self ._arc_width > 1 and HAVE_VECTORIO and self ._fill is not None :
119
+ if self .palette is None :
120
+ self .palette = displayio .Palette (1 )
121
+ self .palette [0 ] = self ._fill
122
+ if self .vector_polygon is None :
123
+ self .vector_polygon = vectorio .Polygon (
124
+ pixel_shader = self .palette , points = points , x = 0 , y = 0
125
+ )
126
+ self .append (self .vector_polygon )
127
+ else :
128
+ self .vector_polygon .points = points
129
+
130
+ if self ._outline is not None :
131
+ if self .outline_polygon is None :
132
+ self .outline_polygon = Polygon (
133
+ points , outline = self ._outline , colors = 1 , close = self ._arc_width > 1
134
+ )
135
+ else :
136
+ self .remove (self .outline_polygon )
137
+ self .outline_polygon = Polygon (
138
+ points , outline = self ._outline , colors = 1 , close = self ._arc_width > 1
139
+ )
140
+ self .append (self .outline_polygon )
141
+
142
+ @property
143
+ def direction (self ):
144
+ """Which direction the arc is pointing"""
145
+ return self ._direction
146
+
147
+ @direction .setter
148
+ def direction (self , value ):
149
+ self ._direction = value
150
+ self ._direction = value - self .angle / 2
151
+ self ._init_arc ()
152
+
153
+ @property
154
+ def radius (self ):
155
+ """Radius of the arc"""
156
+ return self ._radius
157
+
158
+ @radius .setter
159
+ def radius (self , value ):
160
+ self ._radius = value
161
+ self ._init_arc ()
162
+
163
+ @property
164
+ def angle (self ):
165
+ """How wide the curve of the arc is in degrees"""
166
+ return self ._angle
167
+
168
+ @angle .setter
169
+ def angle (self , value ):
170
+ self ._angle = value
171
+ self ._init_arc ()
172
+
173
+ @property
174
+ def segments (self ):
175
+ """Number of segments of the arc, more segments make smoother
176
+ rounded parts but use more time and memory"""
177
+ return self ._segments
178
+
179
+ @segments .setter
180
+ def segments (self , value ):
181
+ self ._segments = value
182
+ self ._init_arc ()
183
+
184
+ @property
185
+ def outline (self ):
186
+ """The outline color. None for no outline"""
187
+ return self ._outline
188
+
189
+ @outline .setter
190
+ def outline (self , value ):
191
+ self ._outline = value
192
+ self ._init_arc ()
193
+
194
+ @property
195
+ def fill (self ):
196
+ """The fill color. None for no fill"""
197
+ return self ._fill
198
+
199
+ @fill .setter
200
+ def fill (self , value ):
201
+ self ._fill = value
202
+ self ._init_arc ()
203
+
204
+ @property
205
+ def arc_width (self ):
206
+ """The thickness of the arc in pixels"""
207
+ return self ._arc_width
208
+
209
+ @arc_width .setter
210
+ def arc_width (self , value ):
211
+ self ._arc_width = value
212
+ self ._init_arc ()
0 commit comments