4.8. A Few More turtle Methods and Observations¶
Here are a few more things that you might find useful as you write programs that use turtles.
Turtle methods can use negative angles or distances. So
turtle.forward(-100)
will move the turtle backwards, andturtle.left(-30)
turns it to the right. Additionally, because there are 360 degrees in a circle, turning 30 to the left will leave you facing in the same direction as turning 330 to the right! (The on-screen animation will differ, though — you will be able to tell if tess is turning clockwise or counter-clockwise!)This suggests that we don’t need both a left and a right turn method — we could be minimalists, and just have one method. There is also a backward method. (If you are very nerdy, you might enjoy saying
turtle.backward(-100)
to move the turtle forward!)Part of thinking like a scientist is to understand more of the structure and rich relationships in your field. So reviewing a few basic facts about geometry and number lines, like we’ve done here is a good start if we’re going to play with turtles.
A turtle’s pen can be picked up or put down. This allows us to move a turtle to a different place without drawing a line. The methods are
penup
andpendown
.turtle.penup() turtle.forward(100.0) # this moves the turtle, but no line is drawn turtle.down()
You can speed up or slow down the turtle’s animation speed. (Animation controls how quickly the turtle turns and moves forward). Speed settings can be set between 1 (slowest) to 10 (fastest). But if you set the speed to 0, it has a special meaning — turn off animation and go as fast as possible.
turtle.speed(10)