46
46
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
47
47
"""
48
48
49
- #pylint:disable=too-many-public-methods,invalid-name, too-many-instance-attributes
50
- #pylint:disable=too-few-public-methods,too-many-lines
49
+ #pylint:disable=too-many-public-methods, too-many-instance-attributes, invalid-name
50
+ #pylint:disable=too-few-public-methods, too-many-lines, too-many-arguments
51
51
52
52
import gc
53
53
import math
@@ -185,6 +185,7 @@ def __init__(self, display=board.DISPLAY):
185
185
186
186
self ._penstate = False
187
187
self ._pencolor = None
188
+ self ._pensize = 1
188
189
self .pencolor (Color .WHITE )
189
190
190
191
self ._display .show (self ._splash )
@@ -287,7 +288,8 @@ def goto(self, x1, y1=None):
287
288
while (not rev and x0 <= x1 ) or (rev and x1 <= x0 ):
288
289
if steep :
289
290
try :
290
- self ._fg_bitmap [int (y0 ), int (x0 )] = self ._pencolor
291
+ self ._plot (int (y0 ), int (x0 ), self ._pencolor )
292
+ # self._fg_bitmap[int(y0), int(x0)] = self._pencolor
291
293
except IndexError :
292
294
pass
293
295
self ._x = y0
@@ -296,7 +298,8 @@ def goto(self, x1, y1=None):
296
298
time .sleep (0.003 )
297
299
else :
298
300
try :
299
- self ._fg_bitmap [int (x0 ), int (y0 )] = self ._pencolor
301
+ self ._plot (int (x0 ), int (y0 ), self ._pencolor )
302
+ # self._fg_bitmap[int(x0), int(y0)] = self._pencolor
300
303
except IndexError :
301
304
pass
302
305
self ._x = x0
@@ -357,6 +360,60 @@ def home(self):
357
360
self .setheading (90 )
358
361
self .goto (0 , 0 )
359
362
363
+ def _plot (self , x , y , c ):
364
+ try :
365
+ self ._fg_bitmap [int (x ), int (y )] = c
366
+ except IndexError :
367
+ pass
368
+
369
+ def _draw_disk (self , x , y , width , height , r , color , fill = True , outline = True , stroke = 1 ):
370
+ """Draw a filled and/or outlined circle"""
371
+ if fill :
372
+ self ._helper (x + r , y + r , r , color = color , fill = True ,
373
+ x_offset = width - 2 * r - 1 , y_offset = height - 2 * r - 1 )
374
+ if outline :
375
+ self ._helper (x + r , y + r , r , color = color , stroke = stroke ,
376
+ x_offset = width - 2 * r - 1 , y_offset = height - 2 * r - 1 )
377
+
378
+ # pylint: disable=too-many-locals, too-many-branches
379
+ def _helper (self , x0 , y0 , r , color , x_offset = 0 , y_offset = 0 ,
380
+ stroke = 1 , fill = False ):
381
+ """Draw quandrant wedges filled or outlined"""
382
+ f = 1 - r
383
+ ddF_x = 1
384
+ ddF_y = - 2 * r
385
+ x = - 1
386
+ y = r
387
+
388
+ while x < y :
389
+ if f >= 0 :
390
+ y -= 1
391
+ ddF_y += 2
392
+ f += ddF_y
393
+ x += 1
394
+ ddF_x += 2
395
+ f += ddF_x
396
+ if fill :
397
+ for w in range (x0 - y , x0 + y + x_offset ):
398
+ self ._plot (w , y0 + x + y_offset , color )
399
+ self ._plot (w , y0 - x , color )
400
+ for w in range (x0 - x , x0 + x + x_offset ):
401
+ self ._plot (w , y0 + y + y_offset , color )
402
+ self ._plot (w , y0 - y , color )
403
+ else :
404
+ for line in range (stroke ):
405
+ self ._plot (x0 - y + line , y0 + x + y_offset , color )
406
+ self ._plot (x0 - x , y0 + y + y_offset - line , color )
407
+ self ._plot (x0 - y + line , y0 - x , color )
408
+ self ._plot (x0 - x , y0 - y + line , color )
409
+ for line in range (stroke ):
410
+ self ._plot (x0 + x + x_offset , y0 + y + y_offset - line , color )
411
+ self ._plot (x0 + y + x_offset - line , y0 + x + y_offset , color )
412
+ self ._plot (x0 + x + x_offset , y0 - y + line , color )
413
+ self ._plot (x0 + y + x_offset - line , y0 - x , color )
414
+
415
+ # pylint: enable=too-many-locals, too-many-branches
416
+
360
417
def circle (self , radius , extent = None , steps = None ):
361
418
"""Not implemented
362
419
@@ -380,7 +437,7 @@ def circle(self, radius, extent=None, steps=None):
380
437
raise NotImplementedError
381
438
382
439
#pylint:disable=keyword-arg-before-vararg
383
- def dot (self , size = None , * color ):
440
+ def dot (self , size = None , color = None ):
384
441
"""Not implemented
385
442
386
443
Draw a circular dot with diameter size, using color.
@@ -391,7 +448,15 @@ def dot(self, size=None, *color):
391
448
:param color: the color of the dot
392
449
393
450
"""
394
- raise NotImplementedError
451
+ if size is None :
452
+ size = max (self ._pensize + 4 , self ._pensize * 2 )
453
+ if color is None :
454
+ color = self ._pencolor
455
+ else :
456
+ color = self ._color_to_pencolor (color )
457
+ self ._logger .debug ('dot(%d)' , size )
458
+ self ._draw_disk (self ._x - size , self ._y - size , 2 * size + 1 , 2 * size + 1 , size , color )
459
+ self ._fg_sprite [0 , 0 ] = 0
395
460
396
461
def stamp (self ):
397
462
"""Not implemented
@@ -555,7 +620,9 @@ def pensize(self, width=None):
555
620
:param width: - a positive number
556
621
557
622
"""
558
- raise NotImplementedError
623
+ if width is not None :
624
+ self ._pensize = width
625
+ return self ._pensize
559
626
width = pensize
560
627
561
628
def pen (self , pen = None , ** pendict ):
@@ -596,6 +663,11 @@ def isdown(self):
596
663
############################################################################
597
664
# Color control
598
665
666
+ #pylint:disable=no-self-use
667
+ def _color_to_pencolor (self , c ):
668
+ return 1 + Color .colors .index (c )
669
+ #pylint:enable=no-self-use
670
+
599
671
def color (self , * args ):
600
672
"""Not implemented
601
673
0 commit comments