MCPcopy Index your code
hub / github.com/python/cpython / circle

Method circle

Lib/turtle.py:2006–2067  ·  view source on GitHub ↗

Draw a circle with given radius. Arguments: radius -- a number extent (optional) -- a number steps (optional) -- an integer Draw a circle with given radius. The center is radius units left of the turtle; extent - an angle - determines which part of

(self, radius, extent = None, steps = None)

Source from the content-addressed store, hash-verified

2004 self._rotate(angle)
2005
2006 def circle(self, radius, extent = None, steps = None):
2007 """ Draw a circle with given radius.
2008
2009 Arguments:
2010 radius -- a number
2011 extent (optional) -- a number
2012 steps (optional) -- an integer
2013
2014 Draw a circle with given radius. The center is radius units left
2015 of the turtle; extent - an angle - determines which part of the
2016 circle is drawn. If extent is not given, draw the entire circle.
2017 If extent is not a full circle, one endpoint of the arc is the
2018 current pen position. Draw the arc in counterclockwise direction
2019 if radius is positive, otherwise in clockwise direction. Finally
2020 the direction of the turtle is changed by the amount of extent.
2021
2022 As the circle is approximated by an inscribed regular polygon,
2023 steps determines the number of steps to use. If not given,
2024 it will be calculated automatically. Maybe used to draw regular
2025 polygons.
2026
2027 call: circle(radius) # full circle
2028 --or: circle(radius, extent) # arc
2029 --or: circle(radius, extent, steps)
2030 --or: circle(radius, steps=6) # 6-sided polygon
2031
2032 Example (for a Turtle instance named turtle):
2033 >>> turtle.circle(50)
2034 >>> turtle.circle(120, 180) # semicircle
2035 """
2036 if self.undobuffer:
2037 self.undobuffer.push(["seq"])
2038 self.undobuffer.cumulate = True
2039 speed = self.speed()
2040 if extent is None:
2041 extent = self._fullcircle
2042 if steps is None:
2043 frac = abs(extent)/self._fullcircle
2044 steps = 1+int(min(11+abs(radius)/6.0, 59.0)*frac)
2045 w = 1.0 * extent / steps
2046 w2 = 0.5 * w
2047 l = 2.0 * radius * math.sin(math.radians(w2)*self._degreesPerAU)
2048 if radius < 0:
2049 l, w, w2 = -l, -w, -w2
2050 tr = self._tracer()
2051 dl = self._delay()
2052 if speed == 0:
2053 self._tracer(0, 0)
2054 else:
2055 self.speed(0)
2056 self._rotate(w2)
2057 for i in range(steps):
2058 self.speed(speed)
2059 self._go(l)
2060 self.speed(0)
2061 self._rotate(w)
2062 self._rotate(-w2)
2063 if speed == 0:

Callers 1

mainFunction · 0.80

Calls 8

speedMethod · 0.95
_tracerMethod · 0.95
_delayMethod · 0.95
_rotateMethod · 0.95
_goMethod · 0.95
absFunction · 0.85
radiansMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected