@@ -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.)
@@ -367,9 +370,7 @@ def _plot(self, x, y, c):
367
370
pass
368
371
369
372
def circle (self , radius , extent = None , steps = None ):
370
- """Not implemented
371
-
372
- Draw a circle with given radius. The center is radius units left of
373
+ """Draw a circle with given radius. The center is radius units left of
373
374
the turtle; extent - an angle - determines which part of the circle is
374
375
drawn. If extent is not given, draw the entire circle. If extent is not
375
376
a full circle, one endpoint of the arc is the current pen position.
@@ -384,9 +385,27 @@ def circle(self, radius, extent=None, steps=None):
384
385
:param radius: the radius of the circle
385
386
:param extent: the arc of the circle to be drawn
386
387
:param steps: how many points along the arc are computed
387
-
388
388
"""
389
- raise NotImplementedError
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 )
390
409
391
410
def _draw_disk (self , x , y , width , height , r , color , fill = True , outline = True , stroke = 1 ):
392
411
"""Draw a filled and/or outlined circle"""
@@ -509,7 +528,6 @@ def speed(self, speed=None):
509
528
"normal": 6
510
529
"slow": 3
511
530
"slowest": 1
512
-
513
531
Speeds from 1 to 10 enforce increasingly faster animation of line
514
532
drawing and turtle turning.
515
533
@@ -576,21 +594,27 @@ def distance(self, x1, y1=None):
576
594
############################################################################
577
595
# Setting and measurement
578
596
579
- def degrees (self , fullcircle = 360 ):
580
- """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.
605
+
581
606
582
- Set angle measurement units, i.e. set number of "degrees" for a full circle.
607
+ def degrees (self , fullcircle = 360 ):
608
+ """Set angle measurement units, i.e. set number of "degrees" for a full circle.
583
609
Default value is 360 degrees.
584
610
585
611
:param fullcircle: the number of degrees in a full circle
586
612
"""
587
- raise NotImplementedError
613
+ self . _setDegreesPerAU ( fullcircle )
588
614
589
615
def radians (self ):
590
- """Not implemented
591
-
592
- Set the angle measurement units to radians. Equivalent to degrees(2*math.pi)."""
593
- raise NotImplementedError
616
+ """Set the angle measurement units to radians. Equivalent to degrees(2*math.pi)."""
617
+ self ._setDegreesPerAU (2 * math .pi )
594
618
595
619
596
620
############################################################################
0 commit comments