user1794625
user1794625

Reputation: 105

Draw faster circles with Python turtle

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

Answers (5)

Amelie
Amelie

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

enter image description here

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

Gokul
Gokul

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

hola
hola

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

user1908430
user1908430

Reputation: 61

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

Upvotes: 1

RichieHindle
RichieHindle

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

Related Questions