@@ -147,6 +147,10 @@ def __init__(self, display=board.DISPLAY):
147
147
self ._speed = 6
148
148
self ._heading = 90
149
149
self ._logomode = False
150
+ self ._fullcircle = 360.0
151
+ self ._degreesPerAU = 1.0
152
+ self ._mode = "standard"
153
+ self ._angleOffset = 0
150
154
151
155
self ._splash = displayio .Group (max_size = 3 )
152
156
@@ -222,7 +226,6 @@ def backward(self, distance):
222
226
self .forward (- distance )
223
227
bk = backward
224
228
back = backward
225
-
226
229
def right (self , angle ):
227
230
"""Turn turtle right by angle units. (Units are by default degrees,
228
231
but can be set via the degrees() and radians() functions.)
@@ -366,6 +369,44 @@ def _plot(self, x, y, c):
366
369
except IndexError :
367
370
pass
368
371
372
+ def circle (self , radius , extent = None , steps = None ):
373
+ """Draw a circle with given radius. The center is radius units left of
374
+ the turtle; extent - an angle - determines which part of the circle is
375
+ drawn. If extent is not given, draw the entire circle. If extent is not
376
+ a full circle, one endpoint of the arc is the current pen position.
377
+ Draw the arc in counterclockwise direction if radius is positive,
378
+ otherwise in clockwise direction. Finally the direction of the turtle
379
+ is changed by the amount of extent.
380
+
381
+ As the circle is approximated by an inscribed regular polygon, steps
382
+ determines the number of steps to use. If not given, it will be
383
+ calculated automatically. May be used to draw regular polygons.
384
+
385
+ :param radius: the radius of the circle
386
+ :param extent: the arc of the circle to be drawn
387
+ :param steps: how many points along the arc are computed
388
+ """
389
+ # call: circle(radius) # full circle
390
+ # --or: circle(radius, extent) # arc
391
+ # --or: circle(radius, extent, steps)
392
+ # --or: circle(radius, steps=6) # 6-sided polygon
393
+
394
+ if extent is None :
395
+ extent = self ._fullcircle
396
+ if steps is None :
397
+ frac = abs (extent )/ self ._fullcircle
398
+ steps = 1 + int (min (11 + abs (radius )/ 6.0 , 59.0 )* frac )
399
+ w = 1.0 * extent / steps
400
+ w2 = 0.5 * w
401
+ l = 2.0 * radius * math .sin (w2 * math .pi / 180.0 * self ._degreesPerAU )
402
+ if radius < 0 :
403
+ l , w , w2 = - l , - w , - w2
404
+ self .left (w2 )
405
+ for _ in range (steps ):
406
+ self .forward (l )
407
+ self .left (w )
408
+ self .right (w2 )
409
+
369
410
def _draw_disk (self , x , y , width , height , r , color , fill = True , outline = True , stroke = 1 ):
370
411
"""Draw a filled and/or outlined circle"""
371
412
if fill :
@@ -414,33 +455,9 @@ def _helper(self, x0, y0, r, color, x_offset=0, y_offset=0,
414
455
415
456
# pylint: enable=too-many-locals, too-many-branches
416
457
417
- def circle (self , radius , extent = None , steps = None ):
418
- """Not implemented
419
-
420
- Draw a circle with given radius. The center is radius units left of
421
- the turtle; extent - an angle - determines which part of the circle is
422
- drawn. If extent is not given, draw the entire circle. If extent is not
423
- a full circle, one endpoint of the arc is the current pen position.
424
- Draw the arc in counterclockwise direction if radius is positive,
425
- otherwise in clockwise direction. Finally the direction of the turtle
426
- is changed by the amount of extent.
427
-
428
- As the circle is approximated by an inscribed regular polygon, steps
429
- determines the number of steps to use. If not given, it will be
430
- calculated automatically. May be used to draw regular polygons.
431
-
432
- :param radius: the radius of the circle
433
- :param extent: the arc of the circle to be drawn
434
- :param steps: how many points along the arc are computed
435
-
436
- """
437
- raise NotImplementedError
438
-
439
458
#pylint:disable=keyword-arg-before-vararg
440
459
def dot (self , size = None , color = None ):
441
- """Not implemented
442
-
443
- Draw a circular dot with diameter size, using color.
460
+ """Draw a circular dot with diameter size, using color.
444
461
If size is not given, the maximum of pensize+4 and
445
462
2*pensize is used.
446
463
@@ -511,7 +528,6 @@ def speed(self, speed=None):
511
528
"normal": 6
512
529
"slow": 3
513
530
"slowest": 1
514
-
515
531
Speeds from 1 to 10 enforce increasingly faster animation of line
516
532
drawing and turtle turning.
517
533
@@ -578,21 +594,27 @@ def distance(self, x1, y1=None):
578
594
############################################################################
579
595
# Setting and measurement
580
596
581
- def degrees (self , fullcircle = 360 ):
582
- """Not implemented
597
+ def _setDegreesPerAU (self , fullcircle ):
598
+ """Helper function for degrees() and radians()"""
599
+ self ._fullcircle = fullcircle
600
+ self ._degreesPerAU = 360 / fullcircle
601
+ if self ._mode == "standard" :
602
+ self ._angleOffset = 0
603
+ else :
604
+ self ._angleOffset = fullcircle / 4.
583
605
584
- Set angle measurement units, i.e. set number of "degrees" for a full circle.
606
+
607
+ def degrees (self , fullcircle = 360 ):
608
+ """Set angle measurement units, i.e. set number of "degrees" for a full circle.
585
609
Default value is 360 degrees.
586
610
587
611
:param fullcircle: the number of degrees in a full circle
588
612
"""
589
- raise NotImplementedError
613
+ self . _setDegreesPerAU ( fullcircle )
590
614
591
615
def radians (self ):
592
- """Not implemented
593
-
594
- Set the angle measurement units to radians. Equivalent to degrees(2*math.pi)."""
595
- raise NotImplementedError
616
+ """Set the angle measurement units to radians. Equivalent to degrees(2*math.pi)."""
617
+ self ._setDegreesPerAU (2 * math .pi )
596
618
597
619
598
620
############################################################################
0 commit comments