@@ -215,6 +215,32 @@ def vline(self, x, y, height, color):
215
215
"""Draw a vertical line up to a given length."""
216
216
self .rect (x , y , 1 , height , color , fill = True )
217
217
218
+ def circle (self , center_x , center_y , radius , color ):
219
+ """Draw a circle at the given midpoint location, radius and color.
220
+ The ```circle``` method draws only a 1 pixel outline."""
221
+ x = radius - 1
222
+ y = 0
223
+ d_x = 1
224
+ d_y = 1
225
+ err = d_x - (radius << 1 )
226
+ while x >= y :
227
+ self .pixel (center_x + x , center_y + y , color )
228
+ self .pixel (center_x + y , center_y + x , color )
229
+ self .pixel (center_x - y , center_y + x , color )
230
+ self .pixel (center_x - x , center_y + y , color )
231
+ self .pixel (center_x - x , center_y - y , color )
232
+ self .pixel (center_x - y , center_y - x , color )
233
+ self .pixel (center_x + y , center_y - x , color )
234
+ self .pixel (center_x + x , center_y - y , color )
235
+ if err <= 0 :
236
+ y += 1
237
+ err += d_y
238
+ d_y += 2
239
+ if err > 0 :
240
+ x -= 1
241
+ d_x += 2
242
+ err += d_x - (radius << 1 )
243
+
218
244
def rect (self , x , y , width , height , color , * , fill = False ):
219
245
"""Draw a rectangle at the given location, size and color. The ```rect``` method draws only
220
246
a 1 pixel outline."""
0 commit comments