Module turtle :: Class RawPen
[hide private]
[frames] | no frames]

_ClassType RawPen

Known Subclasses:

Instance Methods [hide private]
 
__init__(self, canvas)
 
degrees(self, fullcircle=360.0)
Set angle measurement units to degrees.
 
radians(self)
Set the angle measurement units to radians.
 
reset(self)
Clear the screen, re-center the pen, and set variables to the default values.
 
clear(self)
Clear the screen.
 
tracer(self, flag)
Set tracing on if flag is True, and off if it is False.
 
forward(self, distance)
Go forward distance steps.
 
backward(self, distance)
Go backwards distance steps.
 
left(self, angle)
Turn left angle units (units are by default degrees, but can be set via the degrees() and radians() functions.)
 
right(self, angle)
Turn right angle units (units are by default degrees, but can be set via the degrees() and radians() functions.)
 
up(self)
Pull the pen up -- no drawing when moving.
 
down(self)
Put the pen down -- draw when moving.
 
width(self, width)
Set the line to thickness to width.
 
color(self, *args)
Set the pen color.
 
_set_color(self, color)
 
write(self, text, move=False)
Write text at the current pen position.
 
fill(self, flag)
Call fill(1) before drawing the shape you want to fill, and fill(0) when done.
 
begin_fill(self)
Called just before drawing a shape to be filled.
 
end_fill(self)
Called after drawing a shape to be filled.
 
circle(self, radius, extent=None)
Draw a circle with given radius.
 
heading(self)
Return the turtle's current heading.
 
setheading(self, angle)
Set the turtle facing the given angle.
 
window_width(self)
Returns the width of the turtle window.
 
window_height(self)
Return the height of the turtle window.
 
position(self)
Return the current (x, y) location of the turtle.
 
setx(self, xpos)
Set the turtle's x coordinate to be xpos.
 
sety(self, ypos)
Set the turtle's y coordinate to be ypos.
 
towards(self, *args)
Returs the angle, which corresponds to the line from turtle-position to point (x,y).
 
goto(self, *args)
Go to the given point.
 
_goto(self, x1, y1)
 
speed(self, speed)
Set the turtle's speed.
 
delay(self, delay)
Set the drawing delay in milliseconds.
 
_draw_turtle(self, position=[])
 
_delete_turtle(self)
Method Details [hide private]

degrees(self, fullcircle=360.0)

 

Set angle measurement units to degrees.

Example: >>> turtle.degrees()

radians(self)

 

Set the angle measurement units to radians.

Example: >>> turtle.radians()

reset(self)

 

Clear the screen, re-center the pen, and set variables to the default values.

Example: >>> turtle.position() [0.0, -22.0] >>> turtle.heading() 100.0 >>> turtle.reset() >>> turtle.position() [0.0, 0.0] >>> turtle.heading() 0.0

clear(self)

 

Clear the screen. The turtle does not move.

Example: >>> turtle.clear()

tracer(self, flag)

 

Set tracing on if flag is True, and off if it is False. Tracing means line are drawn more slowly, with an animation of an arrow along the line.

Example: >>> turtle.tracer(False) # turns off Tracer

forward(self, distance)

 

Go forward distance steps.

Example: >>> turtle.position() [0.0, 0.0] >>> turtle.forward(25) >>> turtle.position() [25.0, 0.0] >>> turtle.forward(-75) >>> turtle.position() [-50.0, 0.0]

backward(self, distance)

 

Go backwards distance steps.

The turtle's heading does not change.

Example: >>> turtle.position() [0.0, 0.0] >>> turtle.backward(30) >>> turtle.position() [-30.0, 0.0]

left(self, angle)

 

Turn left angle units (units are by default degrees, but can be set via the degrees() and radians() functions.)

When viewed from above, the turning happens in-place around its front tip.

Example: >>> turtle.heading() 22 >>> turtle.left(45) >>> turtle.heading() 67.0

right(self, angle)

 

Turn right angle units (units are by default degrees, but can be set via the degrees() and radians() functions.)

When viewed from above, the turning happens in-place around its front tip.

Example: >>> turtle.heading() 22 >>> turtle.right(45) >>> turtle.heading() 337.0

up(self)

 

Pull the pen up -- no drawing when moving.

Example: >>> turtle.up()

down(self)

 

Put the pen down -- draw when moving.

Example: >>> turtle.down()

width(self, width)

 

Set the line to thickness to width.

Example: >>> turtle.width(10)

color(self, *args)

 
Set the pen color.

Three input formats are allowed:

    color(s)
    s is a Tk specification string, such as "red" or "yellow"

    color((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..1]

    color(r, g, b)
    r, g, and b represent an RGB color, and each of r, g, and b
    are in the range [0..1]

Example:

>>> turtle.color('brown')
>>> tup = (0.2, 0.8, 0.55)
>>> turtle.color(tup)
>>> turtle.color(0, .5, 0)

write(self, text, move=False)

 

Write text at the current pen position.

If move is true, the pen is moved to the bottom-right corner of the text. By default, move is False.

Example: >>> turtle.write('The race is on!') >>> turtle.write('Home = (0, 0)', True)

fill(self, flag)

 
Call fill(1) before drawing the shape you
 want to fill, and fill(0) when done.

Example:
>>> turtle.fill(1)
>>> turtle.forward(100)
>>> turtle.left(90)
>>> turtle.forward(100)
>>> turtle.left(90)
>>> turtle.forward(100)
>>> turtle.left(90)
>>> turtle.forward(100)
>>> turtle.fill(0)

begin_fill(self)

 
Called just before drawing a shape to be filled.
    Must eventually be followed by a corresponding end_fill() call.
    Otherwise it will be ignored.

Example:
>>> turtle.begin_fill()
>>> turtle.forward(100)
>>> turtle.left(90)
>>> turtle.forward(100)
>>> turtle.left(90)
>>> turtle.forward(100)
>>> turtle.left(90)
>>> turtle.forward(100)
>>> turtle.end_fill()

end_fill(self)

 

Called after drawing a shape to be filled.

Example: >>> turtle.begin_fill() >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.end_fill()

circle(self, radius, extent=None)

 

Draw a circle with given radius. The center is radius units left of the turtle; extent determines which part of the circle is drawn. If not given, the entire circle is drawn.

If extent is not a full circle, one endpoint of the arc is the current pen position. The arc is drawn in a counter clockwise direction if radius is positive, otherwise in a clockwise direction. In the process, the direction of the turtle is changed by the amount of the extent.

>>> turtle.circle(50)
>>> turtle.circle(120, 180)  # half a circle

heading(self)

 

Return the turtle's current heading.

Example: >>> turtle.heading() 67.0

setheading(self, angle)

 
Set the turtle facing the given angle.

Here are some common directions in degrees:

   0 - east
  90 - north
 180 - west
 270 - south

Example:
>>> turtle.setheading(90)
>>> turtle.heading()
90
>>> turtle.setheading(128)
>>> turtle.heading()
128

window_width(self)

 

Returns the width of the turtle window.

Example: >>> turtle.window_width() 640

window_height(self)

 

Return the height of the turtle window.

Example: >>> turtle.window_height() 768

position(self)

 

Return the current (x, y) location of the turtle.

Example: >>> turtle.position() [0.0, 240.0]

setx(self, xpos)

 

Set the turtle's x coordinate to be xpos.

Example: >>> turtle.position() [10.0, 240.0] >>> turtle.setx(10) >>> turtle.position() [10.0, 240.0]

sety(self, ypos)

 

Set the turtle's y coordinate to be ypos.

Example: >>> turtle.position() [0.0, 0.0] >>> turtle.sety(-22) >>> turtle.position() [0.0, -22.0]

towards(self, *args)

 

Returs the angle, which corresponds to the line from turtle-position to point (x,y).

Argument can be two coordinates or one pair of coordinates or a RawPen/Pen instance.

Example: >>> turtle.position() [10.0, 10.0] >>> turtle.towards(0,0) 225.0

goto(self, *args)

 
Go to the given point.

If the pen is down, then a line will be drawn. The turtle's
orientation does not change.

Two input formats are accepted:

   goto(x, y)
   go to point (x, y)

   goto((x, y))
   go to point (x, y)

Example:
>>> turtle.position()
[0.0, 0.0]
>>> turtle.goto(50, -45)
>>> turtle.position()
[50.0, -45.0]

speed(self, speed)

 
Set the turtle's speed.

speed must one of these five strings:

    'fastest' is a 0 ms delay
    'fast' is a 5 ms delay
    'normal' is a 10 ms delay
    'slow' is a 15 ms delay
    'slowest' is a 20 ms delay

 Example:
 >>> turtle.speed('slow')

delay(self, delay)

 

Set the drawing delay in milliseconds.

This is intended to allow finer control of the drawing speed than the speed() method

Example: >>> turtle.delay(15)