Reputation: 105
I have an exercise wherein I have to draw a lot of circles with Python turtle. I have set speed(0)
and I am using:
from turtle import*
speed(0)
i=0
while i < 360:
forward(1)
left(1)
i+=1
to draw circles. It takes so long. Is there any faster way?
Upvotes: 3
Views: 10726
Reputation: 41
Turtle has a function for drawing circles and the speed of that is much faster than going in a circle one step at a time.
import turtle
tina=turtle.Turtle()
tina.circle(70)
It will look like this
If you want to draw your circle even faster, you can try adding a delay block as well.
import turtle
tina=turtle.Turtle()
tina.delay(1)
tina.speed(0)
Upvotes: 2
Reputation: 1
Use Multithread to draw two semi circles simultaneously. Initially the turtle will be at (0,0) so just clone the turtle and make them both face in opposite direction by 180° then draw semicircles. The code is below:
from threading import Thread
import turtle
t = turtle.Turtle()
t.speed(0)
def semi1(r):
r.circle(50,180)
def semi2(t):
t.circle(50,180)
r = t.clone()
r.rt(180)
a = Thread(target=semi1).start()
b = Thread(target=semi2).start()
This may draw the circle fast.
Upvotes: 0
Reputation: 950
Have you tried turtle.delay()
or turtle.tracer()
? See documentation here and here. These set options for screen refreshing which is responsible for most of the delays.
Upvotes: 6
Reputation: 61
The circle() method might not be faster, but may be easier to manage: turtle.circle()
Upvotes: 1
Reputation: 281495
You could draw fewer segments, so rather than 360 you go for 120:
while i < 360:
forward(3)
left(3)
i+=3
That will make your circle less smooth, but three times faster to draw.
Upvotes: 1