2
votes

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?

4
What do you mean by faster. As in code performance or the speed of the turtle? It's not clear what you're trying to do and what you want to do. - Glen Selle
This clearly isn't your actual code, as i isn't initialised. This would produce a NameError. Please give your real code if you want help. Beyond that, if you want to loop a number of times in Python, counting like that is considered bad practice. Use for _ in range(360): instead. - Gareth Latty
isnt there something like turtle.circle? - Ant

4 Answers

6
votes

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.

1
votes

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.

1
votes

The circle() method might not be faster, but may be easier to manage: turtle.circle()

0
votes

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.