The Turtle, by default, is an arrow and appears on the screen facing to the right. From there, your code affects the movement of the turtle. The 2 most basic movements are:
- t.forward()
- t.backward()
When written in your code, these two lines will cause the turtle to move either forward or backward, by the number of steps that you decide to put into the brackets.
Run the code below to see an example of how these commands work:
While the two commands listed above are useful for getting your turtle moving, by themselves they can only really draw a horizontal line. If we want to draw shapes, we need our turtle to rotate, or turn! To do this we use these two commands:
- t.right()
- t.left()
Using right() will turn the turtle clockwise while using left() will turn the turtle counterclockwise. To tell the turtle by how much we want it to turn, we use degrees inside the bracket. For example, if we want to draw shapes with perpendicular corners (like squares) we would use a 90 inside the brackets to make the corner.
Another movement that is useful is the t.goto() command. This allows us to directly send the Turtle to a place on our screen, without having to use any other commands. In the brackets, you must put coordinates in the format (x,y).
This can be useful for drawing diagonal lines, or moving your Turtle to a specific place before you begin drawing your desired shape or picture.