ipycc.turtle
A class to describe a virtual turtle robot drawing on a screen.
Display the turtle's drawing sceen.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
Move the turtle forward by the specified distance.
Argument:
distance -- a number (integer or float)
Move the turtle forward by the specified distance, in the direction
the turtle is headed.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
print(t.position()) # (0.00, 0.00)
t.forward(25)
print(t.position()) # (25.00,0.00)
t.forward(-75)
print(t.position()) # (-50.00,0.00)
Move the turtle forward by the specified distance.
Argument:
distance -- a number (integer or float)
Move the turtle forward by the specified distance, in the direction
the turtle is headed.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
print(t.position()) # (0.00, 0.00)
t.forward(25)
print(t.position()) # (25.00,0.00)
t.forward(-75)
print(t.position()) # (-50.00,0.00)
Move the turtle backward by distance.
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.position()) # (0.00, 0.00)
t.backward(30)
print(t.position()) # (-30.00, 0.00)
Move the turtle backward by distance.
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.position()) # (0.00, 0.00)
t.backward(30)
print(t.position()) # (-30.00, 0.00)
Move the turtle backward by distance.
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.position()) # (0.00, 0.00)
t.backward(30)
print(t.position()) # (-30.00, 0.00)
Turn turtle right by angle units.
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() methods.)
Angle orientation depends on mode. (See this.)
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's heading before and after turning.
print(t.heading()) # 22.0
t.right(45)
print(t.heading()) # 337.0
Turn turtle right by angle units.
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() methods.)
Angle orientation depends on mode. (See this.)
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's heading before and after turning.
print(t.heading()) # 22.0
t.right(45)
print(t.heading()) # 337.0
Turn turtle left by angle units.
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() methods.)
Angle orientation depends on mode.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's heading before and after turning.
print(t.heading()) # 22.0
t.left(45)
print(t.heading()) # 67.0
Turn turtle left by angle units.
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() methods.)
Angle orientation depends on mode.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's heading before and after turning.
print(t.heading()) # 22.0
t.left(45)
print(t.heading()) # 67.0
Move turtle to an absolute position.
Aliases: setpos | setposition | goto:
Arguments:
x-- a number or vectory-- a number (optional)
call: goto(x, y) # two coordinates
Move turtle to an absolute position. If the pen is down, a line will be drawn. The turtle's orientation does not change.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.pos()) # (0.00, 0.00)
t.goto(60, 30)
print(t.pos()) # (60.00, 30.00)
Move turtle to an absolute position.
Aliases: setpos | setposition | goto:
Arguments:
x-- a number or vectory-- a number (optional)
call: goto(x, y) # two coordinates
Move turtle to an absolute position. If the pen is down, a line will be drawn. The turtle's orientation does not change.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.pos()) # (0.00, 0.00)
t.goto(60, 30)
print(t.pos()) # (60.00, 30.00)
Move turtle to an absolute position.
Aliases: setpos | setposition | goto:
Arguments:
x-- a number or vectory-- a number (optional)
call: goto(x, y) # two coordinates
Move turtle to an absolute position. If the pen is down, a line will be drawn. The turtle's orientation does not change.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.pos()) # (0.00, 0.00)
t.goto(60, 30)
print(t.pos()) # (60.00, 30.00)
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.position()) # (0.00, 240.00)
t.setx(10)
print(t.position()) # (10.00, 240.00)
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position before and after moving.
print(t.position()) # (0.00, 40.00)
t.sety(-10)
print(t.position()) # (0.00, -10.00)
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:
- 0 - east
- 90 - north
- 180 - west
- 270 - south
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's heading and print it.
t.setheading(90)
print(t.heading()) # 90
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:
- 0 - east
- 90 - north
- 180 - west
- 270 - south
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's heading and print it.
t.setheading(90)
print(t.heading()) # 90
Move turtle to the origin - coordinates (0,0).
No arguments.
Move turtle to the origin and reset its heading to 0.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Move the turtle forward, then move it back home.
t.forward(100)
t.home()
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Draw dots.
t.dot()
t.forward(50)
t.dot(20, "blue")
t.forward(50)
Stamp a copy of the turtleshape onto the canvas.
No argument.
Stamp a copy of the turtle shape onto the canvas at the current turtle position.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Draw a stamp and move.
t.color("blue")
t.stamp()
t.forward(50)
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's speed.
t.speed(3)
Return the turtle's current location (x,y), as a Vec2D.
No arguments.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position.
print(t.pos()) # (0.00, 0.00)
Return the turtle's current location (x,y), as a Vec2D.
No arguments.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position.
print(t.pos()) # (0.00, 0.00)
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 instancey-- a number (optional)
Return the angle, between the line from turtle-position to position
specified by x, y and the turtle's start orientation.
Example
from ipycc.turtle import Turtle, showscreen, Vec2D
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position and heading.
print(t.pos()) # (10.00, 10.00)
print(t.towards(0, 0)) # 225.0
print(t.towards((0, 0))) # 225.0
v = Vec2D(0, 0)
print(t.towards(v)) # 225.0
Return the turtle's x coordinate.
No arguments.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Move the turtle and print its x-coordinate.
t.left(60)
t.forward(100)
print(tutrtle.xcor()) # 50.0
Return the turtle's y coordinate.
No arguments.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Move the turtle and print its y-coordinate.
t.left(60)
t.forward(100)
print(t.ycor()) # 86.6025403784
Return the turtle's current heading.
No arguments.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Turn the turtle and print its heading.
t.left(67)
print(t.heading()) # 67.0
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 instancey-- a number (optional)
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's position and distance to a point.
print(t.pos()) # (0.00, 0.00)
print(t.distance(30, 40)) # 50.0
# Create another turtle.
t2 = Turtle()
# Move the second turtle and print its distance from
# the first turtle.
t2.forward(77)
print(t.distance(t2)) # 77.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. Default value is 360 degrees.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Turn the turtle and print its heading.
t.left(90)
print(t.heading()) # 90
# Change angle measurement unit to grad (also known as gon,
# grade, or gradian and equals 1/100-th of the right angle.)
t.degrees(400.0)
print(t.heading()) # 100
Set the angle measurement units to radians.
No arguments.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's heading in degrees and radians.
print(t.heading()) # 90
t.radians()
print(t.heading()) # 1.5707963267948966
Pull the pen down -- drawing when moving.
No argument.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Put the turtle's pen down and move.
t.pendown()
t.forward(100)
Pull the pen down -- drawing when moving.
No argument.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Put the turtle's pen down and move.
t.pendown()
t.forward(100)
Pull the pen down -- drawing when moving.
No argument.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Put the turtle's pen down and move.
t.pendown()
t.forward(100)
Pull the pen up -- no drawing when moving.
No argument
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Pick the turtle's pen up and move.
t.penup()
t.forward(100)
Pull the pen up -- no drawing when moving.
No argument
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Pick the turtle's pen up and move.
t.penup()
t.forward(100)
Pull the pen up -- no drawing when moving.
No argument
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Pick the turtle's pen up and move.
t.penup()
t.forward(100)
Set or return the line thickness.
Argument:
width -- positive number
Set the line thickness to width or return it. If no argument is
given, current pensize is returned.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's pen size and move.
print(t.pensize()) # 1
t.forward(50)
# Change the turtle's pen size and move.
t.pensize(10) # from here on lines of width 10 are drawn
t.forward(50)
Set or return the line thickness.
Argument:
width -- positive number
Set the line thickness to width or return it. If no argument is
given, current pensize is returned.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's pen size and move.
print(t.pensize()) # 1
t.forward(50)
# Change the turtle's pen size and move.
t.pensize(10) # from here on lines of width 10 are drawn
t.forward(50)
Return True if pen is down, False if it's up.
No argument.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Pick the turtle's pen up and print its state.
t.penup()
print(t.isdown()) # False
# Put the turtle's pen down and print its state.
t.pendown()
print(t.isdown()) # True
Return the colormode or set it to 1.0 or 255.
Optional argument:
cmode -- one of the values 1.0 or 255
r, g, b values of colortriples have to be in range 0..cmode.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's default color mode.
print(t.colormode()) # 1.0
# Change the turtle's color mode and change its color.
t.colormode(255)
t.color(240, 160, 80)
Return or set the pencolor and fillcolor.
Arguments: Several input formats are allowed. They use 0, 1, 2, or 3 arguments as follows:
color()returns the current pencolor and the current fillcolor as a pair of color specification strings.color(colorstring),color((r,g,b)),color(r,g,b)sets bothfillcolor()andpencolor()to the given value.color(colorstring1, colorstring2),color((r1,g1,b1), (r2,g2,b2))setspencolor(colorstring1)andfillcolor(colorstring2)orpencolor((r1,g1,b1))andfillcolor((r2,g2,b2)).
If turtleshape is a polygon, outline and interior of that polygon is drawn with the newly set colors.
For more info see: pencolor(), fillcolor()
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's pen and fill color, then print them.
t.color('red', 'green')
print(t.color()) # ('red', 'green')
# Change the color mode.
t.colormode(255)
# Set the turtle's pen and fill color, then print them.
t.color((40, 80, 120), (160, 200, 240))
print(t.color()) # ('#285078', '#a0c8f0')
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)a Tk color specification string, such as"red"or"yellow"pencolor((r, g, b))a tuple ofr,g, andb, which represent, an RGB color, and each ofr,g, andbare in the range0..colormode, wherecolormodeis either 1.0 or 255pencolor(r, g, b)r,g, andbrepresent an RGB color, and each ofr,g, andbare in the range0..colormode
If turtleshape is a polygon, the outline of that polygon is drawn with the newly set pencolor.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's pen color to brown, then print it.
t.pencolor('brown')
print(t.pencolor()) # 'brown'
# Set the turtle's pen color using a tuple, then print it.
tup = (0.2, 0.8, 0.55)
t.pencolor(tup)
print(t.pencolor()) # '#33cc8c'
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)a Tk color specification string, such as"red"or"yellow"fillcolor((r, g, b))a tuple ofr,g, andb, which represent, an RGB color, and each ofr,g, andbare in the range0..colormode, wherecolormodeis either 1.0 or 255fillcolor(r, g, b)r,g, andbrepresent an RGB color, and each ofr,g, andbare in the range0..colormode
If turtleshape is a polygon, the interior of that polygon is drawn with the newly set fillcolor.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's fill color to violet.
t.fillcolor('violet')
# Set the turtle's fill color to its pen color.
col = t.pencolor()
t.fillcolor(col)
# Set the turtle's fill color using RGB values.
t.fillcolor(0, 0.5, 0)
Return fillstate (True if filling, False otherwise).
No argument.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Begin filling.
t.begin_fill()
# Change the turtle's pen size if it is filling.
if t.filling():
t.pensize(5)
else:
t.pensize(3)
Called just before drawing a shape to be filled.
No argument.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's pen and fill colors.
t.color("black", "red")
# Begin filling.
t.begin_fill()
# Begin creating a polygon.
t.begin_poly()
for i in range(4):
t.forward(50)
t.left(90)
t.end_poly()
# Stop creating a polygon.
t.end_fill()
# Stop filling.
Fill the shape drawn after the call begin_fill().
No argument.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's pen and fill color.
t.color("black", "red")
# Begin filling.
t.begin_fill()
# Begin creating a polygon.
t.begin_poly()
for i in range(4):
t.forward(50)
t.left(90)
t.end_poly()
# Stop creating a polygon.
t.end_fill()
# Stop filling.
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's pen and fill color.
t.color("black", "red")
# Begin filling.
t.begin_fill()
# Begin creating a polygon.
t.begin_poly()
for i in range(4):
t.forward(50)
t.left(90)
# Stop creating a polygon.
t.end_poly()
# Stop filling.
t.end_fill()
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
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's pen and fill color.
t.color("black", "red")
# Begin filling.
t.begin_fill()
# Begin creating a polygon.
t.begin_poly()
for i in range(4):
t.forward(50)
t.left(90)
# Stop creating a polygon.
t.end_poly()
# Stop filling.
t.end_fill()
Return the turtle to its initial state and clear its drawings from the screen.
No arguments.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Move the turtle forward.
t.forward(50)
# Reset the turtle.
t.reset()
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.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Move the turtle forward.
t.forward(50)
# Clear the turtle's drawings.
t.clear()
Write text at the current turtle position.
Arguments:
arg-- info, which is to be written to the screenalign(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 current
turtle position according to align ("left", "center" or "right")
and with the given font.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Write messages to the screen.
t.write('Home = ', align="center")
t.write((0, 0))
Make the turtle visible.
Aliases: showturtle | st
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Hide the turtle.
t.hideturtle()
# Show the turtle.
t.showturtle()
Make the turtle visible.
Aliases: showturtle | st
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Hide the turtle.
t.hideturtle()
# Show the turtle.
t.showturtle()
Make the turtle invisible.
Aliases: hideturtle | ht
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Hide the turtle.
t.hideturtle()
# Show the turtle.
t.showturtle()
Make the turtle invisible.
Aliases: hideturtle | ht
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Hide the turtle.
t.hideturtle()
# Show the turtle.
t.showturtle()
Return True if the turtle is shown, False if it's hidden.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Hide the turtle and print whether it is visible.
t.hideturtle()
print(t.isvisible()) # False
# Show the turtle and print whether it is visible.
t.showturtle()
print(t.isvisible()) # True
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.
Valid shapenames are:
"arrow""turtle""circle""square""triangle""classic"
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Print the turtle's default shape.
print(t.shape()) # 'arrow'
# Change the turtle's shape and print it.
t.shape("turtle")
print(t.shape()) # 'turtle'
Set/return turtle's stretchfactors/outline. Set resizemode to "user".
Optional arguments:
stretch_wid: positive numberstretch_len: positive numberoutline: positive number
Return or set the pen's attributes x/y-stretchfactors and/or outline. The turtle will be displayed stretched according to its stretchfactors:
stretch_widis stretchfactor perpendicular to orientation.stretch_lenis stretchfactor in direction of the turtle's orientation.outlinedetermines the width of the shapes's outline.
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Change the turtle's shape size.
t.shapesize(5, 5, 12)
t.shapesize(outline=8)
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. Doesn't change the
turtle's heading (direction of movement).
If shear is not given: return the current shearfactor, i. e. the
tangent of the shear angle, by which lines parallel to the
heading of the turtle are sheared.
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's shape and size.
t.shape("circle")
t.shapesize(5, 2)
# Set the turtle's shear factor and print it.
t.shearfactor(0.5)
print(t.shearfactor()) # 0.5
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. Doesn't change the turtle's
heading (direction of movement).
If angle is not given: return the current tilt-angle, i. e. the angle
between the orientation of the turtleshape and the heading of the
turtle (its direction of movement).
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's shape and size.
t.shape("circle")
t.shapesize(5, 2)
# Print the turtle's tilt angle.
print(t.tiltangle()) # 0.0
# Tilt the turtle and print the angle.
t.tiltangle(45)
print(t.tiltangle()) # 45.0
# Stamp the turtle's shape.
t.stamp()
# Move the turtle forward.
t.forward(50)
# Tilt the turtle back to its original angle and print it.
t.tiltangle(-45)
print(t.tiltangle()) # 315.0
# Stamp the turtle's shape and move forward.
t.stamp()
t.forward(50)
Rotate the turtleshape by angle.
Argument:
angle - a number
Rotate the turtleshape by angle from its current tilt-angle,
but don't change the turtle's heading (direction of movement).
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the turtle's shape and size.
t.shape("circle")
t.shapesize(5, 2)
# Tilt the turtle and move forward.
t.tilt(30)
t.forward(50)
# Tilt the turtle again and move forward.
t.tilt(30)
t.forward(50)
Set or return backgroundcolor of the turtle's screen.
Arguments: Four input formats are allowed:
bgcolor()Return the current background as color specification string, possibly in hex-number format (see example). May be used as input to another color/pencolor/fillcolor call.bgcolor(colorstring)a Tk color specification string, such as"red"or"yellow"bgcolor((r, g, b))a tuple ofr,g, andb, which represent, an RGB color, and each ofr,g, andbare in the range0..colormode, wherecolormodeis either 1.0 or 255bgcolor(r, g, b)r,g, andbrepresent an RGB color, and each ofr,g, andbare in the range0..colormode
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Set the screen's background color and print it.
t.bgcolor("orange")
print(t.bgcolor()) # 'orange'
A 2 dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs also. Derived from tuple, so a vector is a tuple!
Provides (for a, b vectors, k number):
a+bvector additiona-bvector subtractiona*binner productk*aanda*kmultiplication with scalar|a|absolute value ofaa.rotate(angle)rotation
Returns a vector with the same magnitude that is rotated counterclockwise by a given angle.
Argument: angle -- a number
Example
from ipycc.turtle import Vec2D
v1 = Vec2D(1, 0)
v2 = v1.rotate(90)
print(v1) # (1.00,0.00)
print(v2) # (0.00,1.00)
Turns turtle animation on/off for updating drawings.
The parameter, n, must be either 0 (off) or 1 (on).
Example
from ipycc.turtle import Turtle, showscreen, tracer
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Draw without animation.
tracer(0)
for i in range(100):
length = i * 5
t.forward(length)
t.left(90)
tracer(1)
Sets the size of the screen.
Arguments:
width-- a numberheight-- a number
The first two arguments, width and height, set the width of the
drawing screen in pixels.
Calling setup() will resize the screen and all turtles will be reset.
Example
from ipycc.turtle import Turtle, showscreen, setup
# Show the screen.
showscreen()
# Set the screen to half size.
setup(200, 200)
# Create a turtle.
t = Turtle()
Shows the screen to which turtles are drawing.
Calling showscreen() displays the drawing screen beneath the
code cell in which it's called.
Example
from ipycc.turtle import Turtle, showscreen
# Show the screen.
showscreen()
# Create a turtle and move it.
t = Turtle()
t.forward(100)
# Create a turtle and move it.
t2 = Turtle()
for i in range(4):
t2.forward(50)
t2.left(90)
Delete all drawings from the screen.
Resets the now empty screen to its initial state with a white background.
Calling clearscreen() resets all turtles on the screen.
Example
from ipycc.turtle import Turtle, showscreen. clearscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Move the turtle forward.
t.forward(100)
# Clear the screen.
clearscreen()
Reset all turtles on the screen to their initial state.
Calling resetscreen() resets all turtles on the screen.
Example
from ipycc.turtle import Turtle, showscreen, resetscreen
# Show the screen.
showscreen()
# Create a turtle.
t = Turtle()
# Move the turtle forward.
t.forward(100)
# Reset the screen.
resetscreen()