desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'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
|
'microseconds'
| @property
def microseconds(self):
| return self._microseconds
|
'Constructor.
Arguments:
year, month, day (required, base 1)'
| def __new__(cls, year, month=None, day=None):
| if (isinstance(year, bytes) and (len(year) == 4) and (1 <= year[2] <= 12) and (month is None)):
self = object.__new__(cls)
self.__setstate(year)
return self
_check_date_fields(year, month, day)
self = object.__new__(cls)
self._year = year
self._month = month
self._day = d... |
'Construct a date from a POSIX timestamp (like time.time()).'
| @classmethod
def fromtimestamp(cls, t):
| (y, m, d, hh, mm, ss, weekday, jday, dst) = _time.localtime(t)
return cls(y, m, d)
|
'Construct a date from time.time().'
| @classmethod
def today(cls):
| t = _time.time()
return cls.fromtimestamp(t)
|
'Contruct a date from a proleptic Gregorian ordinal.
January 1 of year 1 is day 1. Only the year, month and day are
non-zero in the result.'
| @classmethod
def fromordinal(cls, n):
| (y, m, d) = _ord2ymd(n)
return cls(y, m, d)
|
'Convert to formal string, for repr().
>>> dt = datetime(2010, 1, 1)
>>> repr(dt)
\'datetime.datetime(2010, 1, 1, 0, 0)\'
>>> dt = datetime(2010, 1, 1, tzinfo=timezone.utc)
>>> repr(dt)
\'datetime.datetime(2010, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)\''
| def __repr__(self):
| return ('%s(%d, %d, %d)' % (('datetime.' + self.__class__.__name__), self._year, self._month, self._day))
|
'Return ctime() style string.'
| def ctime(self):
| weekday = ((self.toordinal() % 7) or 7)
return ('%s %s %2d 00:00:00 %04d' % (_DAYNAMES[weekday], _MONTHNAMES[self._month], self._day, self._year))
|
'Format using strftime().'
| def strftime(self, fmt):
| return _wrap_strftime(self, fmt, self.timetuple())
|
'Return the date formatted according to ISO.
This is \'YYYY-MM-DD\'.
References:
- http://www.w3.org/TR/NOTE-datetime
- http://www.cl.cam.ac.uk/~mgk25/iso-time.html'
| def isoformat(self):
| return ('%04d-%02d-%02d' % (self._year, self._month, self._day))
|
'year (1-9999)'
| @property
def year(self):
| return self._year
|
'month (1-12)'
| @property
def month(self):
| return self._month
|
'day (1-31)'
| @property
def day(self):
| return self._day
|
'Return local time tuple compatible with time.localtime().'
| def timetuple(self):
| return _build_struct_time(self._year, self._month, self._day, 0, 0, 0, (-1))
|
'Return proleptic Gregorian ordinal for the year, month and day.
January 1 of year 1 is day 1. Only the year, month and day values
contribute to the result.'
| def toordinal(self):
| return _ymd2ord(self._year, self._month, self._day)
|
'Return a new date with new values for the specified fields.'
| def replace(self, year=None, month=None, day=None):
| if (year is None):
year = self._year
if (month is None):
month = self._month
if (day is None):
day = self._day
_check_date_fields(year, month, day)
return date(year, month, day)
|
'Hash.'
| def __hash__(self):
| return hash(self._getstate())
|
'Add a date to a timedelta.'
| def __add__(self, other):
| if isinstance(other, timedelta):
o = (self.toordinal() + other.days)
if (0 < o <= _MAXORDINAL):
return date.fromordinal(o)
raise OverflowError('result out of range')
return NotImplemented
|
'Subtract two dates, or a date and a timedelta.'
| def __sub__(self, other):
| if isinstance(other, timedelta):
return (self + timedelta((- other.days)))
if isinstance(other, date):
days1 = self.toordinal()
days2 = other.toordinal()
return timedelta((days1 - days2))
return NotImplemented
|
'Return day of the week, where Monday == 0 ... Sunday == 6.'
| def weekday(self):
| return ((self.toordinal() + 6) % 7)
|
'Return day of the week, where Monday == 1 ... Sunday == 7.'
| def isoweekday(self):
| return ((self.toordinal() % 7) or 7)
|
'Return a 3-tuple containing ISO year, week number, and weekday.
The first ISO week of the year is the (Mon-Sun) week
containing the year\'s first Thursday; everything else derives
from that.
The first week is 1; Monday is 1 ... Sunday is 7.
ISO calendar algorithm taken from
http://www.phys.uu.nl/~vgent/calendar/isocal... | def isocalendar(self):
| year = self._year
week1monday = _isoweek1monday(year)
today = _ymd2ord(self._year, self._month, self._day)
(week, day) = divmod((today - week1monday), 7)
if (week < 0):
year -= 1
week1monday = _isoweek1monday(year)
(week, day) = divmod((today - week1monday), 7)
elif (week... |
'datetime -> string name of time zone.'
| def tzname(self, dt):
| raise NotImplementedError('tzinfo subclass must override tzname()')
|
'datetime -> minutes east of UTC (negative for west of UTC)'
| def utcoffset(self, dt):
| raise NotImplementedError('tzinfo subclass must override utcoffset()')
|
'datetime -> DST offset in minutes east of UTC.
Return 0 if DST not in effect. utcoffset() must include the DST
offset.'
| def dst(self, dt):
| raise NotImplementedError('tzinfo subclass must override dst()')
|
'datetime in UTC -> datetime in local time.'
| def fromutc(self, dt):
| if (not isinstance(dt, datetime)):
raise TypeError('fromutc() requires a datetime argument')
if (dt.tzinfo is not self):
raise ValueError('dt.tzinfo is not self')
dtoff = dt.utcoffset()
if (dtoff is None):
raise ValueError('fromutc() requires a non-N... |
'Constructor.
Arguments:
hour, minute (required)
second, microsecond (default to zero)
tzinfo (default to None)'
| def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
| self = object.__new__(cls)
if (isinstance(hour, bytes) and (len(hour) == 6)):
self.__setstate(hour, (minute or None))
return self
_check_tzinfo_arg(tzinfo)
_check_time_fields(hour, minute, second, microsecond)
self._hour = hour
self._minute = minute
self._second = second
... |
'hour (0-23)'
| @property
def hour(self):
| return self._hour
|
'minute (0-59)'
| @property
def minute(self):
| return self._minute
|
'second (0-59)'
| @property
def second(self):
| return self._second
|
'microsecond (0-999999)'
| @property
def microsecond(self):
| return self._microsecond
|
'timezone info object'
| @property
def tzinfo(self):
| return self._tzinfo
|
'Hash.'
| def __hash__(self):
| tzoff = self.utcoffset()
if (not tzoff):
return hash(self._getstate()[0])
(h, m) = divmod((timedelta(hours=self.hour, minutes=self.minute) - tzoff), timedelta(hours=1))
assert (not (m % timedelta(minutes=1))), 'whole minute'
m //= timedelta(minutes=1)
if (0 <= h < 24):
return ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.