Sometimes it can be time consuming and even boring to watch the turtle instance slowly draw. In that moment the first question that comes to mind is: How to speed up Python turtle!!?
Don’t worry, in this tutorial we will show you how to quickly adjust the drawing speed of your turtle to your liking.
Here is how to use .speed property of Python’s turtle.
turtle.speedproperty defines the speed of your turtle. Here are how the values for adjusting speed of your turtle.
- 1: Slowest setting
- 5: Mid-speed setting
- 10: Faster speed
- 11: Godspeed
Alternatively, you can use o like this:
turtle.speed(0) for the fastest speed. Let’s see some examples to make it more clear.
Example 1: turtle.speed()
After importing turtle, simply apply .speed() method directly to turtle and continue drawing with it. Here is a turtle example:
import turtle turtle.speed(10) for i in range(10): turtle.forward(200) turtle.left(90)
Adjust the speed property to see the different effects on turtle’s speed.
Example 2: Speed of a turtle instance
Sometimes you might want to create a turtle instance and work with that.
The scenario will be pretty much the same and you can change the value of .speed property for that turtle instance.
Let’s boost Alfred the Turtle’s speed a little.
import turtle Alfred = turtle.Turtle() Alfred.speed(0) for i in range(10): Alfred.forward(200) Alfred.left(90)
Example 3: Turtle Speeding up & Speeding down
Here is a fun turtle code example. Turtle’s speed changes inside a loop as it draws.
In the first for loop, turtle will pick up speed and get faster and faster.
In the second for loop, which will draw the inner pattern, turtle will slow down as it draws.
It can be really fun to observe but also it can be very helpful to visually demonstrate fundamental Python coding concepts to your audience.
Here is the tutorial:
import turtle Alfred = turtle.Turtle() Alfred.color("blue") Alfred.penup() Alfred.goto(-75,-75) Alfred.pendown() #Picking up speed for i in range(50): Alfred.speed(i+1) Alfred.forward(150) Alfred.left(85) Alfred.penup() Alfred.goto(-25,-25) Alfred.pendown() Alfred.setheading(0) #Slowing down for i in range(30): Alfred.speed(30-i) Alfred.forward(50) Alfred.left(85) turtle.exitonclick()
In this Python Tutorial, we learned multiple ways to adjust the speed of Python turtle.
We also saw the significance of different speed values that can be assigned to turtle.
Finally, we have demonstrated a couple of examples that show the different speed adjustments for Python turtle.
You can freely share and use this tutorial with your friends or students with the condition of giving attribution to its original source at Holypython.com.
Thank you for visiting and helping us grow!