Full Turtle specification
https://docs.python.org/3/library/turtle.html
Setting up the Turtle environment
Importing the Turtle library
To control the Python Turtle, we need to use a library of commands that are not part of Python by default.
To use and Python library, we need to use the command import and then the name of the library thus:
import turtle
All import statements go at the very top of the program.
Creating the Turtle object
The Turtle object represents a pen. It is this Turtle object that will draw the lines.
It has to have a name - you can call it anything you want. In the slides the Turtle object is usually called 'bob'.
my_turtle = turtle.Turtle()
Note capitalisation - it is important.
Creating the screen for the Turtle to draw on
You can also create a Screen object for the Turtle to draw on (although this isn't always necessary) - you can call it anything you want. In the slides the Screen is called 'wn'.
window = turtle.Screen()
Drawing commands
my_turtle.forward(pixels)
Makes the Turtle move forward by a specified number of pixels.
my_turtle.back(pixels)
Makes the Turtle move backward by a specified number of pixels.
my_turtle.left(degrees) my_turtle.right(degrees)
Makes the Turtle turn to the left or right, by a specified number of degrees.
my_turtle.pendown()
Puts the [virtual] pen down, so that the Turtle will start drawing (the Turtle starts in this state).
my_turtle.penup()
Lifts the [virtual] pen up, so that the Turtle will stop drawing. This is so that you can draw more complex shapes and patterns where the lines do not touch.
my_turtle.width(pixels)
Sets size of the drawing pen. So the line the Turtle will draw will be a specified number of pixels in width.
my_turtle.color("colour")
Sets the colour of the line the Turtle will draw, to the specified colour. The colour needs to be in double-quotes.
my_turtle.speed("speed")
Sets the speed at which the turtle draws to the specified speed, where speed is a range 1 - 10 (where "1" is slowest and "10" is fastest).