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

Method speed

Python/Turtle.py:2037–2073  ·  view source on GitHub ↗

Return or set the turtle's speed. Optional argument: speed -- an integer in the range 0..10 or a speedstring (see below) Set the turtle's speed to an integer value in the range 0 .. 10. If no argument is given: return current speed. If input is a number gr

(self, speed=None)

Source from the content-addressed store, hash-verified

2035 return self._drawing
2036
2037 def speed(self, speed=None):
2038 """ Return or set the turtle's speed.
2039
2040 Optional argument:
2041 speed -- an integer in the range 0..10 or a speedstring (see below)
2042
2043 Set the turtle's speed to an integer value in the range 0 .. 10.
2044 If no argument is given: return current speed.
2045
2046 If input is a number greater than 10 or smaller than 0.5,
2047 speed is set to 0.
2048 Speedstrings are mapped to speedvalues in the following way:
2049 'fastest' : 0
2050 'fast' : 10
2051 'normal' : 6
2052 'slow' : 3
2053 'slowest' : 1
2054 speeds from 1 to 10 enforce increasingly faster animation of
2055 line drawing and turtle turning.
2056
2057 Attention:
2058 speed = 0 : *no* animation takes place. forward/back makes turtle jump
2059 and likewise left/right make the turtle turn instantly.
2060
2061 Example (for a Turtle instance named turtle):
2062 >>> turtle.speed(3)
2063 """
2064 speeds = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
2065 if speed is None:
2066 return self._speed
2067 if speed in speeds:
2068 speed = speeds[speed]
2069 elif 0.5 < speed < 10.5:
2070 speed = int(round(speed))
2071 else:
2072 speed = 0
2073 self.pen(speed=speed)
2074
2075 def color(self, *args):
2076 """Return or set the pencolor and fillcolor.

Callers 3

myFunFunction · 0.45
pong.pyFile · 0.45
demo2Function · 0.45

Calls 1

penMethod · 0.95

Tested by

no test coverage detected