Skip to content

Variables

Turtle Variables

t = Turtle()
u = Turtle()
r = Turtle()
t = Turtle()
l = Turtle()
e = Turtle()

By naming your turtle you can make multiple instances, giving each unique attributes. In other words, the code above makes several turtles which are the same, but each turtle has a different name (or label). You can then change each turtle using functions — making each of them different! When coming up with a name, make them short and to the point as you will be repeating these.

Using Turtle Functions

Some Interesting Functions:

pendown() # By default the pen is down, and it will draw the line behind the turtle.
penup() # Bringing the pen up will remove this line.
width() # Width changes the thickness of the line the pen draws (in pixels).
turtlesize() # It changes the size of the turtle drawing the line.
color() # Color will change the colour of both the line and turtle.
fillcolor() # This will change the colour inside the lines but must be used with:
begin_fill()
end_fill()
speed() # The speed of the turtle drawing. It ranges from 1 (slowest) up to 10 (which you can write as 0).
shape("circle"). # Changes the look of your turtle to a circle.
# You can also change it to a: square, triangle, arrow and turtle.

Examples

t.penup()
t.width(30)
r.width(10)
l.shape("circle")
e.speed(0)
u.speed(9)
u.color("green")

Window Setup / Control

Setting up a window can help you understand parameters. For example knowing the edges of your screen means knowing how far you can draw. Screen/window set up also allows for adding background colours and clearing the canvas.

But First: Let’s Assign Screen to a Variable

This will make your life easier in the long run: writing long names instead of your own label over and over can get tedious. So we can do something like this:

s = Screen()
# So instead of having to write this
Screen.bgcolor("black")
# You can do this
s.bgcolor("black")

Some useful functions:

s.setup(600, 600, 0, 0) # This dictates the screens width, height, x position and y position.
# This can also be done without setting the starting x, y positions.
s.setup(600, 600)
s.resetscreen() # Clears everything on the screen and brings the turtle back to its starting position.
s.bgcolor("")

Checklist

  • I have made multiple turtles.
  • I have named and changed my turtles to do different things.
  • I have named and changed my screen.