desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Return the width of the turtle window.
Example (for a TurtleScreen instance named screen):
>>> screen.window_width()
640'
| def window_width(self):
| return self._window_size()[0]
|
'Return the height of the turtle window.
Example (for a TurtleScreen instance named screen):
>>> screen.window_height()
480'
| def window_height(self):
| return self._window_size()[1]
|
'Return the Canvas of this TurtleScreen.
No argument.
Example (for a Screen instance named screen):
>>> cv = screen.getcanvas()
>>> cv
<turtle.ScrolledCanvas instance at 0x010742D8>'
| def getcanvas(self):
| return self.cv
|
'Return a list of names of all currently available turtle shapes.
No argument.
Example (for a TurtleScreen instance named screen):
>>> screen.getshapes()
[\'arrow\', \'blank\', \'circle\', ... , \'turtle\']'
| def getshapes(self):
| return sorted(self._shapes.keys())
|
'Bind fun to mouse-click event on canvas.
Arguments:
fun -- a function with two arguments, the coordinates of the
clicked point on the canvas.
num -- the number of the mouse-button, defaults to 1
Example (for a TurtleScreen instance named screen)
>>> screen.onclick(goto)
>>> # Subsequently clicking into the TurtleScree... | def onclick(self, fun, btn=1, add=None):
| self._onscreenclick(fun, btn, add)
|
'Bind fun to key-release event of key.
Arguments:
fun -- a function with no arguments
key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
In order to be able to register key-events, TurtleScreen
must have focus. (See method listen.)
Example (for a TurtleScreen instance named screen):
>>> def f():
... fd(50... | def onkey(self, fun, key):
| if (fun is None):
if (key in self._keys):
self._keys.remove(key)
elif (key not in self._keys):
self._keys.append(key)
self._onkeyrelease(fun, key)
|
'Bind fun to key-press event of key if key is given,
or to any key-press-event if no key is given.
Arguments:
fun -- a function with no arguments
key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
In order to be able to register key-events, TurtleScreen
must have focus. (See method listen.)
Example (for a Tur... | def onkeypress(self, fun, key=None):
| if (fun is None):
if (key in self._keys):
self._keys.remove(key)
elif ((key is not None) and (key not in self._keys)):
self._keys.append(key)
self._onkeypress(fun, key)
|
'Set focus on TurtleScreen (in order to collect key-events)
No arguments.
Dummy arguments are provided in order
to be able to pass listen to the onclick method.
Example (for a TurtleScreen instance named screen):
>>> screen.listen()'
| def listen(self, xdummy=None, ydummy=None):
| self._listen()
|
'Install a timer, which calls fun after t milliseconds.
Arguments:
fun -- a function with no arguments.
t -- a number >= 0
Example (for a TurtleScreen instance named screen):
>>> running = True
>>> def f():
... if running:
... fd(50)
... lt(60)
... screen.ontimer(f, 250)
>>> f() ... | def ontimer(self, fun, t=0):
| self._ontimer(fun, t)
|
'Set background image or return name of current backgroundimage.
Optional argument:
picname -- a string, name of a gif-file or "nopic".
If picname is a filename, set the corresponding image as background.
If picname is "nopic", delete backgroundimage, if present.
If picname is None, return the filename of the current b... | def bgpic(self, picname=None):
| if (picname is None):
return self._bgpicname
if (picname not in self._bgpics):
self._bgpics[picname] = self._image(picname)
self._setbgpic(self._bgpic, self._bgpics[picname])
self._bgpicname = picname
|
'Resize the canvas the turtles are drawing on.
Optional arguments:
canvwidth -- positive integer, new width of canvas in pixels
canvheight -- positive integer, new height of canvas in pixels
bg -- colorstring or color-tuple, new backgroundcolor
If no arguments are given, return current (canvaswidth, canvasheight)
Do n... | def screensize(self, canvwidth=None, canvheight=None, bg=None):
| return self._resize(canvwidth, canvheight, bg)
|
'reset turtle to its initial values
Will be overwritten by parent class'
| def reset(self):
| self._position = Vec2D(0.0, 0.0)
self._orient = TNavigator.START_ORIENTATION[self._mode]
|
'Set turtle-mode to \'standard\', \'world\' or \'logo\'.'
| def _setmode(self, mode=None):
| if (mode is None):
return self._mode
if (mode not in ['standard', 'logo', 'world']):
return
self._mode = mode
if (mode in ['standard', 'world']):
self._angleOffset = 0
self._angleOrient = 1
else:
self._angleOffset = (self._fullcircle / 4.0)
self._angle... |
'Helper function for degrees() and radians()'
| def _setDegreesPerAU(self, fullcircle):
| self._fullcircle = fullcircle
self._degreesPerAU = (360 / fullcircle)
if (self._mode == 'standard'):
self._angleOffset = 0
else:
self._angleOffset = (fullcircle / 4.0)
|
'Set angle measurement units to degrees.
Optional argument:
fullcircle - a number
Set angle measurement units, i. e. set number
of \'degrees\' for a full circle. Dafault value is
360 degrees.
Example (for a Turtle instance named turtle):
>>> turtle.left(90)
>>> turtle.heading()
90
Change angle measurement unit to grad... | def degrees(self, fullcircle=360.0):
| self._setDegreesPerAU(fullcircle)
|
'Set the angle measurement units to radians.
No arguments.
Example (for a Turtle instance named turtle):
>>> turtle.heading()
90
>>> turtle.radians()
>>> turtle.heading()
1.5707963267948966'
| def radians(self):
| self._setDegreesPerAU((2 * math.pi))
|
'move turtle forward by specified distance'
| def _go(self, distance):
| ende = (self._position + (self._orient * distance))
self._goto(ende)
|
'Turn turtle counterclockwise by specified angle if angle > 0.'
| def _rotate(self, angle):
| angle *= self._degreesPerAU
self._orient = self._orient.rotate(angle)
|
'move turtle to position end.'
| def _goto(self, end):
| self._position = end
|
'Move the turtle forward by the specified distance.
Aliases: forward | fd
Argument:
distance -- a number (integer or float)
Move the turtle forward by the specified distance, in the direction
the turtle is headed.
Example (for a Turtle instance named turtle):
>>> turtle.position()
(0.00, 0.00)
>>> turtle.forward(25)
>>... | def forward(self, distance):
| self._go(distance)
|
'Move the turtle backward by distance.
Aliases: back | backward | bk
Argument:
distance -- a number
Move the turtle backward by distance ,opposite to the direction the
turtle is headed. Do not change the turtle\'s heading.
Example (for a Turtle instance named turtle):
>>> turtle.position()
(0.00, 0.00)
>>> turtle.backw... | def back(self, distance):
| self._go((- distance))
|
'Turn turtle right by angle units.
Aliases: right | rt
Argument:
angle -- a number (integer or float)
Turn turtle right by angle units. (Units are by default degrees,
but can be set via the degrees() and radians() functions.)
Angle orientation depends on mode. (See this.)
Example (for a Turtle instance named turtle):
>... | def right(self, angle):
| self._rotate((- angle))
|
'Turn turtle left by angle units.
Aliases: left | lt
Argument:
angle -- a number (integer or float)
Turn turtle left by angle units. (Units are by default degrees,
but can be set via the degrees() and radians() functions.)
Angle orientation depends on mode. (See this.)
Example (for a Turtle instance named turtle):
>>> ... | def left(self, angle):
| self._rotate(angle)
|
'Return the turtle\'s current location (x,y), as a Vec2D-vector.
Aliases: pos | position
No arguments.
Example (for a Turtle instance named turtle):
>>> turtle.pos()
(0.00, 240.00)'
| def pos(self):
| return self._position
|
'Return the turtle\'s x coordinate.
No arguments.
Example (for a Turtle instance named turtle):
>>> reset()
>>> turtle.left(60)
>>> turtle.forward(100)
>>> print turtle.xcor()
50.0'
| def xcor(self):
| return self._position[0]
|
'Return the turtle\'s y coordinate
No arguments.
Example (for a Turtle instance named turtle):
>>> reset()
>>> turtle.left(60)
>>> turtle.forward(100)
>>> print turtle.ycor()
86.6025403784'
| def ycor(self):
| return self._position[1]
|
'Move turtle to an absolute position.
Aliases: setpos | setposition | goto:
Arguments:
x -- a number or a pair/vector of numbers
y -- a number None
call: goto(x, y) # two coordinates
--or: goto((x, y)) # a pair (tuple) of coordinates
--or: goto(vec) # e.g. as returned by pos(... | def goto(self, x, y=None):
| if (y is None):
self._goto(Vec2D(*x))
else:
self._goto(Vec2D(x, y))
|
'Move turtle to the origin - coordinates (0,0).
No arguments.
Move turtle to the origin - coordinates (0,0) and set its
heading to its start-orientation (which depends on mode).
Example (for a Turtle instance named turtle):
>>> turtle.home()'
| def home(self):
| self.goto(0, 0)
self.setheading(0)
|
'Set the turtle\'s first coordinate to x
Argument:
x -- a number (integer or float)
Set the turtle\'s first coordinate to x, leave second coordinate
unchanged.
Example (for a Turtle instance named turtle):
>>> turtle.position()
(0.00, 240.00)
>>> turtle.setx(10)
>>> turtle.position()
(10.00, 240.00)'
| def setx(self, x):
| self._goto(Vec2D(x, self._position[1]))
|
'Set the turtle\'s second coordinate to y
Argument:
y -- a number (integer or float)
Set the turtle\'s first coordinate to x, second coordinate remains
unchanged.
Example (for a Turtle instance named turtle):
>>> turtle.position()
(0.00, 40.00)
>>> turtle.sety(-10)
>>> turtle.position()
(0.00, -10.00)'
| def sety(self, y):
| self._goto(Vec2D(self._position[0], y))
|
'Return the distance from the turtle to (x,y) in turtle step units.
Arguments:
x -- a number or a pair/vector of numbers or a turtle instance
y -- a number None None
call: distance(x, y) # two coordinates
--or: distance((x, y)) # a pair (tuple) of coordinates
--or: ... | def distance(self, x, y=None):
| if (y is not None):
pos = Vec2D(x, y)
if isinstance(x, Vec2D):
pos = x
elif isinstance(x, tuple):
pos = Vec2D(*x)
elif isinstance(x, TNavigator):
pos = x._position
return abs((pos - self._position))
|
'Return the angle of the line from the turtle\'s position to (x, y).
Arguments:
x -- a number or a pair/vector of numbers or a turtle instance
y -- a number None None
call: distance(x, y) # two coordinates
--or: distance((x, y)) # a pair (tuple) of coordinates
--or:... | def towards(self, x, y=None):
| if (y is not None):
pos = Vec2D(x, y)
if isinstance(x, Vec2D):
pos = x
elif isinstance(x, tuple):
pos = Vec2D(*x)
elif isinstance(x, TNavigator):
pos = x._position
(x, y) = (pos - self._position)
result = (round(((math.atan2(y, x) * 180.0) / math.pi), 10) % 360.0)... |
'Return the turtle\'s current heading.
No arguments.
Example (for a Turtle instance named turtle):
>>> turtle.left(67)
>>> turtle.heading()
67.0'
| def heading(self):
| (x, y) = self._orient
result = (round(((math.atan2(y, x) * 180.0) / math.pi), 10) % 360.0)
result /= self._degreesPerAU
return ((self._angleOffset + (self._angleOrient * result)) % self._fullcircle)
|
'Set the orientation of the turtle to to_angle.
Aliases: setheading | seth
Argument:
to_angle -- a number (integer or float)
Set the orientation of the turtle to to_angle.
Here are some common directions in degrees:
standard - mode: logo-mode:
0 - east 0 - north
90 - north 90 - eas... | def setheading(self, to_angle):
| angle = ((to_angle - self.heading()) * self._angleOrient)
full = self._fullcircle
angle = (((angle + (full / 2.0)) % full) - (full / 2.0))
self._rotate(angle)
|
'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 the
circle is drawn. If extent is not given, draw the entire circle.
I... | def circle(self, radius, extent=None, steps=None):
| if self.undobuffer:
self.undobuffer.push(['seq'])
self.undobuffer.cumulate = True
speed = self.speed()
if (extent is None):
extent = self._fullcircle
if (steps is None):
frac = (abs(extent) / self._fullcircle)
steps = (1 + int((min((11 + (abs(radius) / 6.0)), 59.0... |
'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... | def resizemode(self, rmode=None):
| if (rmode is None):
return self._resizemode
rmode = rmode.lower()
if (rmode in ['auto', 'user', 'noresize']):
self.pen(resizemode=rmode)
|
'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 (fo... | def pensize(self, width=None):
| if (width is None):
return self._pensize
self.pen(pensize=width)
|
'Pull the pen up -- no drawing when moving.
Aliases: penup | pu | up
No argument
Example (for a Turtle instance named turtle):
>>> turtle.penup()'
| def penup(self):
| if (not self._drawing):
return
self.pen(pendown=False)
|
'Pull the pen down -- drawing when moving.
Aliases: pendown | pd | down
No argument.
Example (for a Turtle instance named turtle):
>>> turtle.pendown()'
| def pendown(self):
| if self._drawing:
return
self.pen(pendown=True)
|
'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'
| def isdown(self):
| return self._drawing
|
'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.
Speedst... | def speed(self, speed=None):
| speeds = {'fastest': 0, 'fast': 10, 'normal': 6, 'slow': 3, 'slowest': 1}
if (speed is None):
return self._speed
if (speed in speeds):
speed = speeds[speed]
elif (0.5 < speed < 10.5):
speed = int(round(speed))
else:
speed = 0
self.pen(speed=speed)
|
'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)), colo... | def color(self, *args):
| if args:
l = len(args)
if (l == 1):
pcolor = fcolor = args[0]
elif (l == 2):
(pcolor, fcolor) = args
elif (l == 3):
pcolor = fcolor = args
pcolor = self._colorstr(pcolor)
fcolor = self._colorstr(fcolor)
self.pen(pencolor=pco... |
'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 a... | def pencolor(self, *args):
| if args:
color = self._colorstr(args)
if (color == self._pencolor):
return
self.pen(pencolor=color)
else:
return self._color(self._pencolor)
|
'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, su... | def fillcolor(self, *args):
| if args:
color = self._colorstr(args)
if (color == self._fillcolor):
return
self.pen(fillcolor=color)
else:
return self._color(self._fillcolor)
|
'Makes the turtle visible.
Aliases: showturtle | st
No argument.
Example (for a Turtle instance named turtle):
>>> turtle.hideturtle()
>>> turtle.showturtle()'
| def showturtle(self):
| self.pen(shown=True)
|
'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()'
| def hideturtle(self):
| self.pen(shown=False)
|
'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'
| def isvisible(self):
| return self._shown
|
'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
"... | def pen(self, pen=None, **pendict):
| _pd = {'shown': self._shown, 'pendown': self._drawing, 'pencolor': self._pencolor, 'fillcolor': self._fillcolor, 'pensize': self._pensize, 'speed': self._speed, 'resizemode': self._resizemode, 'stretchfactor': self._stretchfactor, 'shearfactor': self._shearfactor, 'outline': self._outlinewidth, 'tilt': self._tilt}
... |
'Delete the turtle\'s drawings and restore its default values.
No argument.
Delete the turtle\'s drawings from the screen, re-center the turtle
and set variables to the default values.
Example (for a Turtle instance named turtle):
>>> turtle.position()
(0.00,-22.00)
>>> turtle.heading()
100.0
>>> turtle.reset()
>>> tur... | def reset(self):
| TNavigator.reset(self)
TPen._reset(self)
self._clear()
self._drawturtle()
self._update()
|
'Set or disable undobuffer.
Argument:
size -- an integer or None
If size is an integer an empty undobuffer of given size is installed.
Size gives the maximum number of turtle-actions that can be undone
by the undo() function.
If size is None, no undobuffer is present.
Example (for a Turtle instance named turtle):
>>> t... | def setundobuffer(self, size):
| if ((size is None) or (size <= 0)):
self.undobuffer = None
else:
self.undobuffer = Tbuffer(size)
|
'Return count of entries in the undobuffer.
No argument.
Example (for a Turtle instance named turtle):
>>> while undobufferentries():
... undo()'
| def undobufferentries(self):
| if (self.undobuffer is None):
return 0
return self.undobuffer.nr_of_items()
|
'Delete all of pen\'s drawings'
| def _clear(self):
| self._fillitem = self._fillpath = None
for item in self.items:
self.screen._delete(item)
self.currentLineItem = self.screen._createline()
self.currentLine = []
if self._drawing:
self.currentLine.append(self._position)
self.items = [self.currentLineItem]
self.clearstamps()
... |
'Delete the turtle\'s drawings from the screen. Do not move turtle.
No arguments.
Delete the turtle\'s drawings from the screen. Do not move turtle.
State and position of the turtle as well as drawings of other
turtles are not affected.
Examples (for a Turtle instance named turtle):
>>> turtle.clear()'
| def clear(self):
| self._clear()
self._update()
|
'Perform a Turtle-data update.'
| def _update(self):
| screen = self.screen
if (screen._tracing == 0):
return
elif (screen._tracing == 1):
self._update_data()
self._drawturtle()
screen._update()
screen._delay(screen._delayvalue)
else:
self._update_data()
if (screen._updatecounter == 0):
for... |
'Turns turtle animation on/off and set delay for update drawings.
Optional arguments:
n -- nonnegative integer
delay -- nonnegative integer
If n is given, only each n-th regular screen update is really performed.
(Can be used to accelerate the drawing of complex graphics.)
Second arguments sets delay value (see RawTu... | def _tracer(self, flag=None, delay=None):
| return self.screen.tracer(flag, delay)
|
'Convert colortriples to hexstrings.'
| def _cc(self, args):
| if isinstance(args, str):
return args
try:
(r, g, b) = args
except:
raise TurtleGraphicsError(('bad color arguments: %s' % str(args)))
if (self.screen._colormode == 1.0):
(r, g, b) = [round((255.0 * x)) for x in (r, g, b)]
if (not ((0 <= r <= 255) and (0 <= g... |
'Create and return a clone of the turtle.
No argument.
Create and return a clone of the turtle with same position, heading
and turtle properties.
Example (for a Turtle instance named mick):
mick = Turtle()
joe = mick.clone()'
| def clone(self):
| screen = self.screen
self._newLine(self._drawing)
turtle = self.turtle
self.screen = None
self.turtle = None
q = deepcopy(self)
self.screen = screen
self.turtle = turtle
q.screen = screen
q.turtle = _TurtleImage(screen, self.turtle.shapeIndex)
screen._turtles.append(q)
tt... |
'Set turtle shape to shape with given name / return current shapename.
Optional argument:
name -- a string, which is a valid shapename
Set turtle shape to shape with given name or, if name is not given,
return name of current shape.
Shape with name must exist in the TurtleScreen\'s shape dictionary.
Initially there are... | def shape(self, name=None):
| if (name is None):
return self.turtle.shapeIndex
if (not (name in self.screen.getshapes())):
raise TurtleGraphicsError(('There is no shape named %s' % name))
self.turtle._setshape(name)
self._update()
|
'Set/return turtle\'s stretchfactors/outline. Set resizemode to "user".
Optional arguments:
stretch_wid : positive number
stretch_len : positive number
outline : positive number
Return or set the pen\'s attributes x/y-stretchfactors and/or outline.
Set resizemode to "user".
If and only if resizemode is set to "user", ... | def shapesize(self, stretch_wid=None, stretch_len=None, outline=None):
| if (stretch_wid is stretch_len is outline is None):
(stretch_wid, stretch_len) = self._stretchfactor
return (stretch_wid, stretch_len, self._outlinewidth)
if ((stretch_wid == 0) or (stretch_len == 0)):
raise TurtleGraphicsError('stretch_wid/stretch_len must not be zero')
... |
'Set or return the current shearfactor.
Optional argument: shear -- number, tangent of the shear angle
Shear the turtleshape according to the given shearfactor shear,
which is the tangent of the shear angle. DO NOT change the
turtle\'s heading (direction of movement).
If shear is not given: return the current shearfact... | def shearfactor(self, shear=None):
| if (shear is None):
return self._shearfactor
self.pen(resizemode='user', shearfactor=shear)
|
'Rotate the turtleshape to point in the specified direction
Argument: angle -- number
Rotate the turtleshape to point in the direction specified by angle,
regardless of its current tilt-angle. DO NOT change the turtle\'s
heading (direction of movement).
Examples (for a Turtle instance named turtle):
>>> turtle.shape("c... | def settiltangle(self, angle):
| tilt = (((- angle) * self._degreesPerAU) * self._angleOrient)
tilt = (((tilt * math.pi) / 180.0) % (2 * math.pi))
self.pen(resizemode='user', tilt=tilt)
|
'Set or return the current tilt-angle.
Optional argument: angle -- number
Rotate the turtleshape to point in the direction specified by angle,
regardless of its current tilt-angle. DO NOT change the turtle\'s
heading (direction of movement).
If angle is not given: return the current tilt-angle, i. e. the angle
between ... | def tiltangle(self, angle=None):
| if (angle is None):
tilt = (((- self._tilt) * (180.0 / math.pi)) * self._angleOrient)
return ((tilt / self._degreesPerAU) % self._fullcircle)
else:
self.settiltangle(angle)
|
'Rotate the turtleshape by angle.
Argument:
angle - a number
Rotate the turtleshape by angle from its current tilt-angle,
but do NOT change the turtle\'s heading (direction of movement).
Examples (for a Turtle instance named turtle):
>>> turtle.shape("circle")
>>> turtle.shapesize(5,2)
>>> turtle.tilt(30)
>>> turtle.fd... | def tilt(self, angle):
| self.settiltangle((angle + self.tiltangle()))
|
'Set or return the current transformation matrix of the turtle shape.
Optional arguments: t11, t12, t21, t22 -- numbers.
If none of the matrix elements are given, return the transformation
matrix.
Otherwise set the given elements and transform the turtleshape
according to the matrix consisting of first row t11, t12 and... | def shapetransform(self, t11=None, t12=None, t21=None, t22=None):
| if (t11 is t12 is t21 is t22 is None):
return self._shapetrafo
(m11, m12, m21, m22) = self._shapetrafo
if (t11 is not None):
m11 = t11
if (t12 is not None):
m12 = t12
if (t21 is not None):
m21 = t21
if (t22 is not None):
m22 = t22
if (((t11 * t22) - (t... |
'Computes transformed polygon shapes from a shape
according to current position and heading.'
| def _polytrafo(self, poly):
| screen = self.screen
(p0, p1) = self._position
(e0, e1) = self._orient
e = Vec2D(e0, ((e1 * screen.yscale) / screen.xscale))
(e0, e1) = ((1.0 / abs(e)) * e)
return [((p0 + (((e1 * x) + (e0 * y)) / screen.xscale)), (p1 + ((((- e0) * x) + (e1 * y)) / screen.yscale))) for (x, y) in poly]
|
'Return the current shape polygon as tuple of coordinate pairs.
No argument.
Examples (for a Turtle instance named turtle):
>>> turtle.shape("square")
>>> turtle.shapetransform(4, -1, 0, 2)
>>> turtle.get_shapepoly()
((50, -20), (30, 20), (-50, 20), (-30, -20))'
| def get_shapepoly(self):
| shape = self.screen._shapes[self.turtle.shapeIndex]
if (shape._type == 'polygon'):
return self._getshapepoly(shape._data, (shape._type == 'compound'))
|
'Calculate transformed shape polygon according to resizemode
and shapetransform.'
| def _getshapepoly(self, polygon, compound=False):
| if ((self._resizemode == 'user') or compound):
(t11, t12, t21, t22) = self._shapetrafo
elif (self._resizemode == 'auto'):
l = max(1, (self._pensize / 5.0))
(t11, t12, t21, t22) = (l, 0, 0, l)
elif (self._resizemode == 'noresize'):
return polygon
return tuple([(((t11 * x) ... |
'Manages the correct rendering of the turtle with respect to
its shape, resizemode, stretch and tilt etc.'
| def _drawturtle(self):
| screen = self.screen
shape = screen._shapes[self.turtle.shapeIndex]
ttype = shape._type
titem = self.turtle._item
if (self._shown and (screen._updatecounter == 0) and (screen._tracing > 0)):
self._hidden_from_screen = False
tshape = shape._data
if (ttype == 'polygon'):
... |
'Stamp a copy of the turtleshape onto the canvas and return its id.
No argument.
Stamp a copy of the turtle shape onto the canvas at the current
turtle position. Return a stamp_id for that stamp, which can be
used to delete it by calling clearstamp(stamp_id).
Example (for a Turtle instance named turtle):
>>> turtle.col... | def stamp(self):
| screen = self.screen
shape = screen._shapes[self.turtle.shapeIndex]
ttype = shape._type
tshape = shape._data
if (ttype == 'polygon'):
stitem = screen._createpoly()
if (self._resizemode == 'noresize'):
w = 1
elif (self._resizemode == 'auto'):
w = self._... |
'does the work for clearstamp() and clearstamps()'
| def _clearstamp(self, stampid):
| if (stampid in self.stampItems):
if isinstance(stampid, tuple):
for subitem in stampid:
self.screen._delete(subitem)
else:
self.screen._delete(stampid)
self.stampItems.remove(stampid)
item = ('stamp', stampid)
buf = self.undobuffer
if (item... |
'Delete stamp with given stampid
Argument:
stampid - an integer, must be return value of previous stamp() call.
Example (for a Turtle instance named turtle):
>>> turtle.color("blue")
>>> astamp = turtle.stamp()
>>> turtle.fd(50)
>>> turtle.clearstamp(astamp)'
| def clearstamp(self, stampid):
| self._clearstamp(stampid)
self._update()
|
'Delete all or first/last n of turtle\'s stamps.
Optional argument:
n -- an integer
If n is None, delete all of pen\'s stamps,
else if n > 0 delete first n stamps
else if n < 0 delete last n stamps.
Example (for a Turtle instance named turtle):
>>> for i in range(8):
... turtle.stamp(); turtle.fd(30)
>>> turtle.cle... | def clearstamps(self, n=None):
| if (n is None):
toDelete = self.stampItems[:]
elif (n >= 0):
toDelete = self.stampItems[:n]
else:
toDelete = self.stampItems[n:]
for item in toDelete:
self._clearstamp(item)
self._update()
|
'Move the pen to the point end, thereby drawing a line
if pen is down. All other methods for turtle movement depend
on this one.'
| def _goto(self, end):
| go_modes = (self._drawing, self._pencolor, self._pensize, isinstance(self._fillpath, list))
screen = self.screen
undo_entry = ('go', self._position, end, go_modes, (self.currentLineItem, self.currentLine[:], screen._pointlist(self.currentLineItem), self.items[:]))
if self.undobuffer:
self.undobu... |
'Reverse a _goto. Used for undo()'
| def _undogoto(self, entry):
| (old, new, go_modes, coodata) = entry
(drawing, pc, ps, filling) = go_modes
(cLI, cL, pl, items) = coodata
screen = self.screen
if (abs((self._position - new)) > 0.5):
print 'undogoto: HALLO-DA-STIMMT-WAS-NICHT!'
self.currentLineItem = cLI
self.currentLine = cL
if (pl == [(0, ... |
'Turns pen clockwise by angle.'
| def _rotate(self, angle):
| if self.undobuffer:
self.undobuffer.push(('rot', angle, self._degreesPerAU))
angle *= self._degreesPerAU
neworient = self._orient.rotate(angle)
tracing = self.screen._tracing
if ((tracing == 1) and (self._speed > 0)):
anglevel = (3.0 * self._speed)
steps = (1 + int((abs(angle... |
'Closes current line item and starts a new one.
Remark: if current line became too long, animation
performance (via _drawline) slowed down considerably.'
| def _newLine(self, usePos=True):
| if (len(self.currentLine) > 1):
self.screen._drawline(self.currentLineItem, self.currentLine, self._pencolor, self._pensize)
self.currentLineItem = self.screen._createline()
self.items.append(self.currentLineItem)
else:
self.screen._drawline(self.currentLineItem, top=True)
se... |
'Return fillstate (True if filling, False else).
No argument.
Example (for a Turtle instance named turtle):
>>> turtle.begin_fill()
>>> if turtle.filling():
... turtle.pensize(5)
... else:
... turtle.pensize(3)'
| def filling(self):
| return isinstance(self._fillpath, list)
|
'Called just before drawing a shape to be filled.
No argument.
Example (for a Turtle instance named turtle):
>>> turtle.color("black", "red")
>>> turtle.begin_fill()
>>> turtle.circle(60)
>>> turtle.end_fill()'
| def begin_fill(self):
| if (not self.filling()):
self._fillitem = self.screen._createpoly()
self.items.append(self._fillitem)
self._fillpath = [self._position]
self._newLine()
if self.undobuffer:
self.undobuffer.push(('beginfill', self._fillitem))
self._update()
|
'Fill the shape drawn after the call begin_fill().
No argument.
Example (for a Turtle instance named turtle):
>>> turtle.color("black", "red")
>>> turtle.begin_fill()
>>> turtle.circle(60)
>>> turtle.end_fill()'
| def end_fill(self):
| if self.filling():
if (len(self._fillpath) > 2):
self.screen._drawpoly(self._fillitem, self._fillpath, fill=self._fillcolor)
if self.undobuffer:
self.undobuffer.push(('dofill', self._fillitem))
self._fillitem = self._fillpath = None
self._update()
|
'Draw a dot with diameter size, using color.
Optional arguments:
size -- an integer >= 1 (if given)
color -- a colorstring or a numeric color tuple
Draw a circular dot with diameter size, using color.
If size is not given, the maximum of pensize+4 and 2*pensize is used.
Example (for a Turtle instance named turtle):
>>>... | def dot(self, size=None, *color):
| if (not color):
if isinstance(size, (str, tuple)):
color = self._colorstr(size)
size = (self._pensize + max(self._pensize, 4))
else:
color = self._pencolor
if (not size):
size = (self._pensize + max(self._pensize, 4))
else:
... |
'Performs the writing for write()'
| def _write(self, txt, align, font):
| (item, end) = self.screen._write(self._position, txt, align, font, self._pencolor)
self.items.append(item)
if self.undobuffer:
self.undobuffer.push(('wri', item))
return end
|
'Write text at the current turtle position.
Arguments:
arg -- info, which is to be written to the TurtleScreen
move (optional) -- True/False
align (optional) -- one of the strings "left", "center" or right"
font (optional) -- a triple (fontname, fontsize, fonttype)
Write text - the string representation of arg - at the... | def write(self, arg, move=False, align='left', font=('Arial', 8, 'normal')):
| if self.undobuffer:
self.undobuffer.push(['seq'])
self.undobuffer.cumulate = True
end = self._write(str(arg), align.lower(), font)
if move:
(x, y) = self.pos()
self.setpos(end, y)
if self.undobuffer:
self.undobuffer.cumulate = False
|
'Start recording the vertices of a polygon.
No argument.
Start recording the vertices of a polygon. Current turtle position
is first point of polygon.
Example (for a Turtle instance named turtle):
>>> turtle.begin_poly()'
| def begin_poly(self):
| self._poly = [self._position]
self._creatingPoly = True
|
'Stop recording the vertices of a polygon.
No argument.
Stop recording the vertices of a polygon. Current turtle position is
last point of polygon. This will be connected with the first point.
Example (for a Turtle instance named turtle):
>>> turtle.end_poly()'
| def end_poly(self):
| self._creatingPoly = False
|
'Return the lastly recorded polygon.
No argument.
Example (for a Turtle instance named turtle):
>>> p = turtle.get_poly()
>>> turtle.register_shape("myFavouriteShape", p)'
| def get_poly(self):
| if (self._poly is not None):
return tuple(self._poly)
|
'Return the TurtleScreen object, the turtle is drawing on.
No argument.
Return the TurtleScreen object, the turtle is drawing on.
So TurtleScreen-methods can be called for that object.
Example (for a Turtle instance named turtle):
>>> ts = turtle.getscreen()
>>> ts
<turtle.TurtleScreen object at 0x0106B770>
>>> ts.bg... | def getscreen(self):
| return self.screen
|
'Return the Turtleobject itself.
No argument.
Only reasonable use: as a function to return the \'anonymous turtle\':
Example:
>>> pet = getturtle()
>>> pet.fd(50)
>>> pet
<turtle.Turtle object at 0x0187D810>
>>> turtles()
[<turtle.Turtle object at 0x0187D810>]'
| def getturtle(self):
| return self
|
'Set delay value which determines speed of turtle animation.'
| def _delay(self, delay=None):
| return self.screen.delay(delay)
|
'Bind fun to mouse-click event on this turtle on canvas.
Arguments:
fun -- a function with two arguments, to which will be assigned
the coordinates of the clicked point on the canvas.
num -- number of the mouse-button defaults to 1 (left mouse button).
add -- True or False. If True, new binding will be added, otherw... | def onclick(self, fun, btn=1, add=None):
| self.screen._onclick(self.turtle._item, fun, btn, add)
self._update()
|
'Bind fun to mouse-button-release event on this turtle on canvas.
Arguments:
fun -- a function with two arguments, to which will be assigned
the coordinates of the clicked point on the canvas.
num -- number of the mouse-button defaults to 1 (left mouse button).
Example (for a MyTurtle instance named joe):
>>> class My... | def onrelease(self, fun, btn=1, add=None):
| self.screen._onrelease(self.turtle._item, fun, btn, add)
self._update()
|
'Bind fun to mouse-move event on this turtle on canvas.
Arguments:
fun -- a function with two arguments, to which will be assigned
the coordinates of the clicked point on the canvas.
num -- number of the mouse-button defaults to 1 (left mouse button).
Every sequence of mouse-move-events on a turtle is preceded by a
mou... | def ondrag(self, fun, btn=1, add=None):
| self.screen._ondrag(self.turtle._item, fun, btn, add)
|
'Does the main part of the work for undo()'
| def _undo(self, action, data):
| if (self.undobuffer is None):
return
if (action == 'rot'):
(angle, degPAU) = data
self._rotate((((- angle) * degPAU) / self._degreesPerAU))
dummy = self.undobuffer.pop()
elif (action == 'stamp'):
stitem = data[0]
self.clearstamp(stitem)
elif (action == 'go... |
'undo (repeatedly) the last turtle action.
No argument.
undo (repeatedly) the last turtle action.
Number of available undo actions is determined by the size of
the undobuffer.
Example (for a Turtle instance named turtle):
>>> for i in range(4):
... turtle.fd(50); turtle.lt(80)
>>> for i in range(8):
... turtle.... | def undo(self):
| if (self.undobuffer is None):
return
item = self.undobuffer.pop()
action = item[0]
data = item[1:]
if (action == 'seq'):
while data:
item = data.pop()
self._undo(item[0], item[1:])
else:
self._undo(action, data)
|
'Set the size and position of the main window.
Arguments:
width: as integer a size in pixels, as float a fraction of the screen.
Default is 50% of screen.
height: as integer the height in pixels, as float a fraction of the
screen. Default is 75% of screen.
startx: if positive, starting position in pixels from the left
... | def setup(self, width=_CFG['width'], height=_CFG['height'], startx=_CFG['leftright'], starty=_CFG['topbottom']):
| if (not hasattr(self._root, 'set_geometry')):
return
sw = self._root.win_width()
sh = self._root.win_height()
if (isinstance(width, float) and (0 <= width <= 1)):
width = (sw * width)
if (startx is None):
startx = ((sw - width) / 2)
if (isinstance(height, float) and (0 <=... |
'Set title of turtle-window
Argument:
titlestring -- a string, to appear in the titlebar of the
turtle graphics window.
This is a method of Screen-class. Not available for TurtleScreen-
objects.
Example (for a Screen instance named screen):
>>> screen.title("Welcome to the turtle-zoo!")'
| def title(self, titlestring):
| if (_Screen._root is not None):
_Screen._root.title(titlestring)
_Screen._title = titlestring
|
'Shut the turtlegraphics window.
Example (for a TurtleScreen instance named screen):
>>> screen.bye()'
| def bye(self):
| self._destroy()
|
'Go into mainloop until the mouse is clicked.
No arguments.
Bind bye() method to mouseclick on TurtleScreen.
If "using_IDLE" - value in configuration dictionary is False
(default value), enter mainloop.
If IDLE with -n switch (no subprocess) is used, this value should be
set to True in turtle.cfg. In this case IDLE\'s ... | def exitonclick(self):
| def exitGracefully(x, y):
'Screen.bye() with two dummy-parameters'
self.bye()
self.onclick(exitGracefully)
if _CFG['using_IDLE']:
return
try:
mainloop()
except AttributeError:
exit(0)
|
'Total seconds in the duration.'
| def total_seconds(self):
| return (((((self.days * 86400) + self.seconds) * (10 ** 6)) + self.microseconds) / (10 ** 6))
|
'days'
| @property
def days(self):
| return self._days
|
'seconds'
| @property
def seconds(self):
| return self._seconds
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.