Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
turtle.TPen Class Reference
Inheritance diagram for turtle.TPen:
Inheritance graph
[legend]
Collaboration diagram for turtle.TPen:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def resizemode
def pensize
def penup
def pendown
def isdown
def speed
def color
def pencolor
def fillcolor
def showturtle
def hideturtle
def isvisible
def pen

Public Attributes

 undobuffer
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _reset

Private Attributes

 _resizemode
 _pensize
 _shown
 _pencolor
 _fillcolor
 _drawing
 _speed
 _stretchfactor
 _shearfactor
 _tilt
 _shapetrafo
 _outlinewidth

Detailed Description

Drawing part of the RawTurtle.
Implements drawing properties.

Definition at line 2021 of file turtle.py.


Constructor & Destructor Documentation

def turtle.TPen.__init__ (   self,
  resizemode = _CFG["resizemode"] 
)

Reimplemented in turtledemo.minimal_hanoi.Disc.

Definition at line 2025 of file turtle.py.

02025 
02026     def __init__(self, resizemode=_CFG["resizemode"]):
02027         self._resizemode = resizemode # or "user" or "noresize"
02028         self.undobuffer = None
02029         TPen._reset(self)

Here is the caller graph for this function:


Member Function Documentation

def turtle.TPen._reset (   self,
  pencolor = _CFG["pencolor"],
  fillcolor = _CFG["fillcolor"] 
) [private]

Definition at line 2031 of file turtle.py.

02031 
02032                      fillcolor=_CFG["fillcolor"]):
02033         self._pensize = 1
02034         self._shown = True
02035         self._pencolor = pencolor
02036         self._fillcolor = fillcolor
02037         self._drawing = True
02038         self._speed = 3
02039         self._stretchfactor = (1., 1.)
02040         self._shearfactor = 0.
02041         self._tilt = 0.
02042         self._shapetrafo = (1., 0., 0., 1.)
02043         self._outlinewidth = 1

def turtle.TPen.color (   self,
  args 
)
Return or set the pencolor and fillcolor.

Arguments:
Several input formats are allowed.
They use 0, 1, 2, or 3 arguments as follows:

color()
    Return the current pencolor and the current fillcolor
    as a pair of color specification strings as are returned
    by pencolor and fillcolor.
color(colorstring), color((r,g,b)), color(r,g,b)
    inputs as in pencolor, set both, fillcolor and pencolor,
    to the given value.
color(colorstring1, colorstring2),
color((r1,g1,b1), (r2,g2,b2))
    equivalent to pencolor(colorstring1) and fillcolor(colorstring2)
    and analogously, if the other input format is used.

If turtleshape is a polygon, outline and interior of that polygon
is drawn with the newly set colors.
For mor info see: pencolor, fillcolor

Example (for a Turtle instance named turtle):
>>> turtle.color('red', 'green')
>>> turtle.color()
('red', 'green')
>>> colormode(255)
>>> color((40, 80, 120), (160, 200, 240))
>>> color()
('#285078', '#a0c8f0')

Definition at line 2176 of file turtle.py.

02176 
02177     def color(self, *args):
02178         """Return or set the pencolor and fillcolor.
02179 
02180         Arguments:
02181         Several input formats are allowed.
02182         They use 0, 1, 2, or 3 arguments as follows:
02183 
02184         color()
02185             Return the current pencolor and the current fillcolor
02186             as a pair of color specification strings as are returned
02187             by pencolor and fillcolor.
02188         color(colorstring), color((r,g,b)), color(r,g,b)
02189             inputs as in pencolor, set both, fillcolor and pencolor,
02190             to the given value.
02191         color(colorstring1, colorstring2),
02192         color((r1,g1,b1), (r2,g2,b2))
02193             equivalent to pencolor(colorstring1) and fillcolor(colorstring2)
02194             and analogously, if the other input format is used.
02195 
02196         If turtleshape is a polygon, outline and interior of that polygon
02197         is drawn with the newly set colors.
02198         For mor info see: pencolor, fillcolor
02199 
02200         Example (for a Turtle instance named turtle):
02201         >>> turtle.color('red', 'green')
02202         >>> turtle.color()
02203         ('red', 'green')
02204         >>> colormode(255)
02205         >>> color((40, 80, 120), (160, 200, 240))
02206         >>> color()
02207         ('#285078', '#a0c8f0')
02208         """
02209         if args:
02210             l = len(args)
02211             if l == 1:
02212                 pcolor = fcolor = args[0]
02213             elif l == 2:
02214                 pcolor, fcolor = args
02215             elif l == 3:
02216                 pcolor = fcolor = args
02217             pcolor = self._colorstr(pcolor)
02218             fcolor = self._colorstr(fcolor)
02219             self.pen(pencolor=pcolor, fillcolor=fcolor)
02220         else:
02221             return self._color(self._pencolor), self._color(self._fillcolor)

Here is the call graph for this function:

def turtle.TPen.fillcolor (   self,
  args 
)
Return or set the fillcolor.

Arguments:
Four input formats are allowed:
  - fillcolor()
    Return the current fillcolor as color specification string,
    possibly in hex-number format (see example).
    May be used as input to another color/pencolor/fillcolor call.
  - fillcolor(colorstring)
    s is a Tk color specification string, such as "red" or "yellow"
  - fillcolor((r, g, b))
    *a tuple* of r, g, and b, which represent, an RGB color,
    and each of r, g, and b are in the range 0..colormode,
    where colormode is either 1.0 or 255
  - fillcolor(r, g, b)
    r, g, and b represent an RGB color, and each of r, g, and b
    are in the range 0..colormode

If turtleshape is a polygon, the interior of that polygon is drawn
with the newly set fillcolor.

Example (for a Turtle instance named turtle):
>>> turtle.fillcolor('violet')
>>> col = turtle.pencolor()
>>> turtle.fillcolor(col)
>>> turtle.fillcolor(0, .5, 0)

Definition at line 2259 of file turtle.py.

02259 
02260     def fillcolor(self, *args):
02261         """ Return or set the fillcolor.
02262 
02263         Arguments:
02264         Four input formats are allowed:
02265           - fillcolor()
02266             Return the current fillcolor as color specification string,
02267             possibly in hex-number format (see example).
02268             May be used as input to another color/pencolor/fillcolor call.
02269           - fillcolor(colorstring)
02270             s is a Tk color specification string, such as "red" or "yellow"
02271           - fillcolor((r, g, b))
02272             *a tuple* of r, g, and b, which represent, an RGB color,
02273             and each of r, g, and b are in the range 0..colormode,
02274             where colormode is either 1.0 or 255
02275           - fillcolor(r, g, b)
02276             r, g, and b represent an RGB color, and each of r, g, and b
02277             are in the range 0..colormode
02278 
02279         If turtleshape is a polygon, the interior of that polygon is drawn
02280         with the newly set fillcolor.
02281 
02282         Example (for a Turtle instance named turtle):
02283         >>> turtle.fillcolor('violet')
02284         >>> col = turtle.pencolor()
02285         >>> turtle.fillcolor(col)
02286         >>> turtle.fillcolor(0, .5, 0)
02287         """
02288         if args:
02289             color = self._colorstr(args)
02290             if color == self._fillcolor:
02291                 return
02292             self.pen(fillcolor=color)
02293         else:
02294             return self._color(self._fillcolor)

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TPen.hideturtle (   self)
Makes the turtle invisible.

Aliases: hideturtle | ht

No argument.

It's a good idea to do this while you're in the
middle of a complicated drawing, because hiding
the turtle speeds up the drawing observably.

Example (for a Turtle instance named turtle):
>>> turtle.hideturtle()

Definition at line 2308 of file turtle.py.

02308 
02309     def hideturtle(self):
02310         """Makes the turtle invisible.
02311 
02312         Aliases: hideturtle | ht
02313 
02314         No argument.
02315 
02316         It's a good idea to do this while you're in the
02317         middle of a complicated drawing, because hiding
02318         the turtle speeds up the drawing observably.
02319 
02320         Example (for a Turtle instance named turtle):
02321         >>> turtle.hideturtle()
02322         """
02323         self.pen(shown=False)

Here is the call graph for this function:

def turtle.TPen.isdown (   self)
Return True if pen is down, False if it's up.

No argument.

Example (for a Turtle instance named turtle):
>>> turtle.penup()
>>> turtle.isdown()
False
>>> turtle.pendown()
>>> turtle.isdown()
True

Definition at line 2123 of file turtle.py.

02123 
02124     def isdown(self):
02125         """Return True if pen is down, False if it's up.
02126 
02127         No argument.
02128 
02129         Example (for a Turtle instance named turtle):
02130         >>> turtle.penup()
02131         >>> turtle.isdown()
02132         False
02133         >>> turtle.pendown()
02134         >>> turtle.isdown()
02135         True
02136         """
02137         return self._drawing

def turtle.TPen.isvisible (   self)
Return True if the Turtle is shown, False if it's hidden.

No argument.

Example (for a Turtle instance named turtle):
>>> turtle.hideturtle()
>>> print turtle.isvisible():
False

Definition at line 2324 of file turtle.py.

02324 
02325     def isvisible(self):
02326         """Return True if the Turtle is shown, False if it's hidden.
02327 
02328         No argument.
02329 
02330         Example (for a Turtle instance named turtle):
02331         >>> turtle.hideturtle()
02332         >>> print turtle.isvisible():
02333         False
02334         """
02335         return self._shown

def turtle.TPen.pen (   self,
  pen = None,
  pendict 
)
Return or set the pen's attributes.

Arguments:
    pen -- a dictionary with some or all of the below listed keys.
    **pendict -- one or more keyword-arguments with the below
         listed keys as keywords.

Return or set the pen's attributes in a 'pen-dictionary'
with the following key/value pairs:
   "shown"      :   True/False
   "pendown"    :   True/False
   "pencolor"   :   color-string or color-tuple
   "fillcolor"  :   color-string or color-tuple
   "pensize"    :   positive number
   "speed"      :   number in range 0..10
   "resizemode" :   "auto" or "user" or "noresize"
   "stretchfactor": (positive number, positive number)
   "shearfactor":   number
   "outline"    :   positive number
   "tilt"       :   number

This dictionary can be used as argument for a subsequent
pen()-call to restore the former pen-state. Moreover one
or more of these attributes can be provided as keyword-arguments.
This can be used to set several pen attributes in one statement.


Examples (for a Turtle instance named turtle):
>>> turtle.pen(fillcolor="black", pencolor="red", pensize=10)
>>> turtle.pen()
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
'pencolor': 'red', 'pendown': True, 'fillcolor': 'black',
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
>>> penstate=turtle.pen()
>>> turtle.color("yellow","")
>>> turtle.penup()
>>> turtle.pen()
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
'pencolor': 'yellow', 'pendown': False, 'fillcolor': '',
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
>>> p.pen(penstate, fillcolor="green")
>>> p.pen()
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
'pencolor': 'red', 'pendown': True, 'fillcolor': 'green',
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}

Definition at line 2336 of file turtle.py.

02336 
02337     def pen(self, pen=None, **pendict):
02338         """Return or set the pen's attributes.
02339 
02340         Arguments:
02341             pen -- a dictionary with some or all of the below listed keys.
02342             **pendict -- one or more keyword-arguments with the below
02343                          listed keys as keywords.
02344 
02345         Return or set the pen's attributes in a 'pen-dictionary'
02346         with the following key/value pairs:
02347            "shown"      :   True/False
02348            "pendown"    :   True/False
02349            "pencolor"   :   color-string or color-tuple
02350            "fillcolor"  :   color-string or color-tuple
02351            "pensize"    :   positive number
02352            "speed"      :   number in range 0..10
02353            "resizemode" :   "auto" or "user" or "noresize"
02354            "stretchfactor": (positive number, positive number)
02355            "shearfactor":   number
02356            "outline"    :   positive number
02357            "tilt"       :   number
02358 
02359         This dictionary can be used as argument for a subsequent
02360         pen()-call to restore the former pen-state. Moreover one
02361         or more of these attributes can be provided as keyword-arguments.
02362         This can be used to set several pen attributes in one statement.
02363 
02364 
02365         Examples (for a Turtle instance named turtle):
02366         >>> turtle.pen(fillcolor="black", pencolor="red", pensize=10)
02367         >>> turtle.pen()
02368         {'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
02369         'pencolor': 'red', 'pendown': True, 'fillcolor': 'black',
02370         'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
02371         >>> penstate=turtle.pen()
02372         >>> turtle.color("yellow","")
02373         >>> turtle.penup()
02374         >>> turtle.pen()
02375         {'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
02376         'pencolor': 'yellow', 'pendown': False, 'fillcolor': '',
02377         'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
02378         >>> p.pen(penstate, fillcolor="green")
02379         >>> p.pen()
02380         {'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
02381         'pencolor': 'red', 'pendown': True, 'fillcolor': 'green',
02382         'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
02383         """
02384         _pd =  {"shown"         : self._shown,
02385                 "pendown"       : self._drawing,
02386                 "pencolor"      : self._pencolor,
02387                 "fillcolor"     : self._fillcolor,
02388                 "pensize"       : self._pensize,
02389                 "speed"         : self._speed,
02390                 "resizemode"    : self._resizemode,
02391                 "stretchfactor" : self._stretchfactor,
02392                 "shearfactor"   : self._shearfactor,
02393                 "outline"       : self._outlinewidth,
02394                 "tilt"          : self._tilt
02395                }
02396 
02397         if not (pen or pendict):
02398             return _pd
02399 
02400         if isinstance(pen, dict):
02401             p = pen
02402         else:
02403             p = {}
02404         p.update(pendict)
02405 
02406         _p_buf = {}
02407         for key in p:
02408             _p_buf[key] = _pd[key]
02409 
02410         if self.undobuffer:
02411             self.undobuffer.push(("pen", _p_buf))
02412 
02413         newLine = False
02414         if "pendown" in p:
02415             if self._drawing != p["pendown"]:
02416                 newLine = True
02417         if "pencolor" in p:
02418             if isinstance(p["pencolor"], tuple):
02419                 p["pencolor"] = self._colorstr((p["pencolor"],))
02420             if self._pencolor != p["pencolor"]:
02421                 newLine = True
02422         if "pensize" in p:
02423             if self._pensize != p["pensize"]:
02424                 newLine = True
02425         if newLine:
02426             self._newLine()
02427         if "pendown" in p:
02428             self._drawing = p["pendown"]
02429         if "pencolor" in p:
02430             self._pencolor = p["pencolor"]
02431         if "pensize" in p:
02432             self._pensize = p["pensize"]
02433         if "fillcolor" in p:
02434             if isinstance(p["fillcolor"], tuple):
02435                 p["fillcolor"] = self._colorstr((p["fillcolor"],))
02436             self._fillcolor = p["fillcolor"]
02437         if "speed" in p:
02438             self._speed = p["speed"]
02439         if "resizemode" in p:
02440             self._resizemode = p["resizemode"]
02441         if "stretchfactor" in p:
02442             sf = p["stretchfactor"]
02443             if isinstance(sf, (int, float)):
02444                 sf = (sf, sf)
02445             self._stretchfactor = sf
02446         if "shearfactor" in p:
02447             self._shearfactor = p["shearfactor"]
02448         if "outline" in p:
02449             self._outlinewidth = p["outline"]
02450         if "shown" in p:
02451             self._shown = p["shown"]
02452         if "tilt" in p:
02453             self._tilt = p["tilt"]
02454         if "stretchfactor" in p or "tilt" in p or "shearfactor" in p:
02455             scx, scy = self._stretchfactor
02456             shf = self._shearfactor
02457             sa, ca = math.sin(self._tilt), math.cos(self._tilt)
02458             self._shapetrafo = ( scx*ca, scy*(shf*ca + sa),
02459                                 -scx*sa, scy*(ca - shf*sa))
02460         self._update()

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TPen.pencolor (   self,
  args 
)
Return or set the pencolor.

Arguments:
Four input formats are allowed:
  - pencolor()
    Return the current pencolor as color specification string,
    possibly in hex-number format (see example).
    May be used as input to another color/pencolor/fillcolor call.
  - pencolor(colorstring)
    s is a Tk color specification string, such as "red" or "yellow"
  - pencolor((r, g, b))
    *a tuple* of r, g, and b, which represent, an RGB color,
    and each of r, g, and b are in the range 0..colormode,
    where colormode is either 1.0 or 255
  - pencolor(r, g, b)
    r, g, and b represent an RGB color, and each of r, g, and b
    are in the range 0..colormode

If turtleshape is a polygon, the outline of that polygon is drawn
with the newly set pencolor.

Example (for a Turtle instance named turtle):
>>> turtle.pencolor('brown')
>>> tup = (0.2, 0.8, 0.55)
>>> turtle.pencolor(tup)
>>> turtle.pencolor()
'#33cc8c'

Definition at line 2222 of file turtle.py.

02222 
02223     def pencolor(self, *args):
02224         """ Return or set the pencolor.
02225 
02226         Arguments:
02227         Four input formats are allowed:
02228           - pencolor()
02229             Return the current pencolor as color specification string,
02230             possibly in hex-number format (see example).
02231             May be used as input to another color/pencolor/fillcolor call.
02232           - pencolor(colorstring)
02233             s is a Tk color specification string, such as "red" or "yellow"
02234           - pencolor((r, g, b))
02235             *a tuple* of r, g, and b, which represent, an RGB color,
02236             and each of r, g, and b are in the range 0..colormode,
02237             where colormode is either 1.0 or 255
02238           - pencolor(r, g, b)
02239             r, g, and b represent an RGB color, and each of r, g, and b
02240             are in the range 0..colormode
02241 
02242         If turtleshape is a polygon, the outline of that polygon is drawn
02243         with the newly set pencolor.
02244 
02245         Example (for a Turtle instance named turtle):
02246         >>> turtle.pencolor('brown')
02247         >>> tup = (0.2, 0.8, 0.55)
02248         >>> turtle.pencolor(tup)
02249         >>> turtle.pencolor()
02250         '#33cc8c'
02251         """
02252         if args:
02253             color = self._colorstr(args)
02254             if color == self._pencolor:
02255                 return
02256             self.pen(pencolor=color)
02257         else:
02258             return self._color(self._pencolor)

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TPen.pendown (   self)
Pull the pen down -- drawing when moving.

Aliases: pendown | pd | down

No argument.

Example (for a Turtle instance named turtle):
>>> turtle.pendown()

Definition at line 2109 of file turtle.py.

02109 
02110     def pendown(self):
02111         """Pull the pen down -- drawing when moving.
02112 
02113         Aliases: pendown | pd | down
02114 
02115         No argument.
02116 
02117         Example (for a Turtle instance named turtle):
02118         >>> turtle.pendown()
02119         """
02120         if self._drawing:
02121             return
02122         self.pen(pendown=True)

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TPen.pensize (   self,
  width = None 
)
Set or return the line thickness.

Aliases:  pensize | width

Argument:
width -- positive number

Set the line thickness to width or return it. If resizemode is set
to "auto" and turtleshape is a polygon, that polygon is drawn with
the same line thickness. If no argument is given, current pensize
is returned.

Example (for a Turtle instance named turtle):
>>> turtle.pensize()
1
turtle.pensize(10)   # from here on lines of width 10 are drawn

Definition at line 2072 of file turtle.py.

02072 
02073     def pensize(self, width=None):
02074         """Set or return the line thickness.
02075 
02076         Aliases:  pensize | width
02077 
02078         Argument:
02079         width -- positive number
02080 
02081         Set the line thickness to width or return it. If resizemode is set
02082         to "auto" and turtleshape is a polygon, that polygon is drawn with
02083         the same line thickness. If no argument is given, current pensize
02084         is returned.
02085 
02086         Example (for a Turtle instance named turtle):
02087         >>> turtle.pensize()
02088         1
02089         turtle.pensize(10)   # from here on lines of width 10 are drawn
02090         """
02091         if width is None:
02092             return self._pensize
02093         self.pen(pensize=width)
02094 

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TPen.penup (   self)
Pull the pen up -- no drawing when moving.

Aliases: penup | pu | up

No argument

Example (for a Turtle instance named turtle):
>>> turtle.penup()

Definition at line 2095 of file turtle.py.

02095 
02096     def penup(self):
02097         """Pull the pen up -- no drawing when moving.
02098 
02099         Aliases: penup | pu | up
02100 
02101         No argument
02102 
02103         Example (for a Turtle instance named turtle):
02104         >>> turtle.penup()
02105         """
02106         if not self._drawing:
02107             return
02108         self.pen(pendown=False)

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TPen.resizemode (   self,
  rmode = None 
)
Set resizemode to one of the values: "auto", "user", "noresize".

(Optional) Argument:
rmode -- one of the strings "auto", "user", "noresize"

Different resizemodes have the following effects:
  - "auto" adapts the appearance of the turtle
   corresponding to the value of pensize.
  - "user" adapts the appearance of the turtle according to the
   values of stretchfactor and outlinewidth (outline),
   which are set by shapesize()
  - "noresize" no adaption of the turtle's appearance takes place.
If no argument is given, return current resizemode.
resizemode("user") is called by a call of shapesize with arguments.


Examples (for a Turtle instance named turtle):
>>> turtle.resizemode("noresize")
>>> turtle.resizemode()
'noresize'

Definition at line 2044 of file turtle.py.

02044 
02045     def resizemode(self, rmode=None):
02046         """Set resizemode to one of the values: "auto", "user", "noresize".
02047 
02048         (Optional) Argument:
02049         rmode -- one of the strings "auto", "user", "noresize"
02050 
02051         Different resizemodes have the following effects:
02052           - "auto" adapts the appearance of the turtle
02053                    corresponding to the value of pensize.
02054           - "user" adapts the appearance of the turtle according to the
02055                    values of stretchfactor and outlinewidth (outline),
02056                    which are set by shapesize()
02057           - "noresize" no adaption of the turtle's appearance takes place.
02058         If no argument is given, return current resizemode.
02059         resizemode("user") is called by a call of shapesize with arguments.
02060 
02061 
02062         Examples (for a Turtle instance named turtle):
02063         >>> turtle.resizemode("noresize")
02064         >>> turtle.resizemode()
02065         'noresize'
02066         """
02067         if rmode is None:
02068             return self._resizemode
02069         rmode = rmode.lower()
02070         if rmode in ["auto", "user", "noresize"]:
02071             self.pen(resizemode=rmode)

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TPen.showturtle (   self)
Makes the turtle visible.

Aliases: showturtle | st

No argument.

Example (for a Turtle instance named turtle):
>>> turtle.hideturtle()
>>> turtle.showturtle()

Definition at line 2295 of file turtle.py.

02295 
02296     def showturtle(self):
02297         """Makes the turtle visible.
02298 
02299         Aliases: showturtle | st
02300 
02301         No argument.
02302 
02303         Example (for a Turtle instance named turtle):
02304         >>> turtle.hideturtle()
02305         >>> turtle.showturtle()
02306         """
02307         self.pen(shown=True)

Here is the call graph for this function:

def turtle.TPen.speed (   self,
  speed = None 
)
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 greater than 10 or smaller than 0.5,
speed is set to 0.
Speedstrings  are mapped to speedvalues in the following way:
    'fastest' :  0
    'fast'    :  10
    'normal'  :  6
    'slow'    :  3
    'slowest' :  1
speeds from 1 to 10 enforce increasingly faster animation of
line drawing and turtle turning.

Attention:
speed = 0 : *no* animation takes place. forward/back makes turtle jump
and likewise left/right make the turtle turn instantly.

Example (for a Turtle instance named turtle):
>>> turtle.speed(3)

Definition at line 2138 of file turtle.py.

02138 
02139     def speed(self, speed=None):
02140         """ Return or set the turtle's speed.
02141 
02142         Optional argument:
02143         speed -- an integer in the range 0..10 or a speedstring (see below)
02144 
02145         Set the turtle's speed to an integer value in the range 0 .. 10.
02146         If no argument is given: return current speed.
02147 
02148         If input is a number greater than 10 or smaller than 0.5,
02149         speed is set to 0.
02150         Speedstrings  are mapped to speedvalues in the following way:
02151             'fastest' :  0
02152             'fast'    :  10
02153             'normal'  :  6
02154             'slow'    :  3
02155             'slowest' :  1
02156         speeds from 1 to 10 enforce increasingly faster animation of
02157         line drawing and turtle turning.
02158 
02159         Attention:
02160         speed = 0 : *no* animation takes place. forward/back makes turtle jump
02161         and likewise left/right make the turtle turn instantly.
02162 
02163         Example (for a Turtle instance named turtle):
02164         >>> turtle.speed(3)
02165         """
02166         speeds = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
02167         if speed is None:
02168             return self._speed
02169         if speed in speeds:
02170             speed = speeds[speed]
02171         elif 0.5 < speed < 10.5:
02172             speed = int(round(speed))
02173         else:
02174             speed = 0
02175         self.pen(speed=speed)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 2036 of file turtle.py.

Definition at line 2035 of file turtle.py.

Definition at line 2042 of file turtle.py.

Definition at line 2034 of file turtle.py.

Definition at line 2032 of file turtle.py.

Reimplemented in turtle.RawTurtle.

Definition at line 2026 of file turtle.py.

Reimplemented in turtle.RawTurtle.

Definition at line 2041 of file turtle.py.

Reimplemented in turtle.RawTurtle.

Definition at line 2039 of file turtle.py.

turtle.TPen._shown [private]

Reimplemented in turtle.RawTurtle.

Definition at line 2033 of file turtle.py.

turtle.TPen._speed [private]

Definition at line 2037 of file turtle.py.

Reimplemented in turtle.RawTurtle.

Definition at line 2038 of file turtle.py.

turtle.TPen._tilt [private]

Reimplemented in turtle.RawTurtle.

Definition at line 2040 of file turtle.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Reimplemented in turtle.RawTurtle.

Definition at line 2027 of file turtle.py.


The documentation for this class was generated from the following file: