MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / circle

Method circle

Python/Turtle.py:1837–1898  ·  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

1835 self._rotate(angle)
1836
1837 def circle(self, radius, extent = None, steps = None):
1838 """ Draw a circle with given radius.
1839
1840 Arguments:
1841 radius -- a number
1842 extent (optional) -- a number
1843 steps (optional) -- an integer
1844
1845 Draw a circle with given radius. The center is radius units left
1846 of the turtle; extent - an angle - determines which part of the
1847 circle is drawn. If extent is not given, draw the entire circle.
1848 If extent is not a full circle, one endpoint of the arc is the
1849 current pen position. Draw the arc in counterclockwise direction
1850 if radius is positive, otherwise in clockwise direction. Finally
1851 the direction of the turtle is changed by the amount of extent.
1852
1853 As the circle is approximated by an inscribed regular polygon,
1854 steps determines the number of steps to use. If not given,
1855 it will be calculated automatically. Maybe used to draw regular
1856 polygons.
1857
1858 call: circle(radius) # full circle
1859 --or: circle(radius, extent) # arc
1860 --or: circle(radius, extent, steps)
1861 --or: circle(radius, steps=6) # 6-sided polygon
1862
1863 Example (for a Turtle instance named turtle):
1864 >>> turtle.circle(50)
1865 >>> turtle.circle(120, 180) # semicircle
1866 """
1867 if self.undobuffer:
1868 self.undobuffer.push(["seq"])
1869 self.undobuffer.cumulate = True
1870 speed = self.speed()
1871 if extent is None:
1872 extent = self._fullcircle
1873 if steps is None:
1874 frac = abs(extent)/self._fullcircle
1875 steps = 1+int(min(11+abs(radius)/6.0, 59.0)*frac)
1876 w = 1.0 * extent / steps
1877 w2 = 0.5 * w
1878 l = 2.0 * radius * math.sin(w2*math.pi/180.0*self._degreesPerAU)
1879 if radius < 0:
1880 l, w, w2 = -l, -w, -w2
1881 tr = self._tracer()
1882 dl = self._delay()
1883 if speed == 0:
1884 self._tracer(0, 0)
1885 else:
1886 self.speed(0)
1887 self._rotate(w2)
1888 for i in range(steps):
1889 self.speed(speed)
1890 self._go(l)
1891 self.speed(0)
1892 self._rotate(w)
1893 self._rotate(-w2)
1894 if speed == 0:

Callers

nothing calls this directly

Calls 6

speedMethod · 0.95
_tracerMethod · 0.95
_delayMethod · 0.95
_rotateMethod · 0.95
_goMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected