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?
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.
circle() 方法可能不会更快,但可能更容易管理: turtle.circle()
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.