[英]How do I make a turtle run faster?
Here's some basic code, how do I make it run faster?这是一些基本代码,如何让它运行得更快?
import turtle
wn = turtle.Screen()
sasha = turtle.Turtle()
length = 12
for i in range(65):
sasha.forward(length)
sasha.right(120)
length = length + 10
you can use speed()
function The more you increase the more you increase the value the more it is slow.你可以使用
speed()
函数,你增加的越多,你增加的值就越慢。
You can use it like this sasha.speed(0
) for example.例如,您可以像
sasha.speed(0
) 这样使用它。
Note:
speed(0)
is the most fast coz the pen will not draw.注意:
speed(0)
是最快的,因为笔不会绘制。
You can use speed()
to change turtle's speed - like in other answer - but you can also turn off animation您可以使用
speed()
来改变乌龟的速度 - 就像在其他答案中一样 - 但你也可以关闭动画
turtle.tracer(False)
and you will have to manually inform turtle when it has to update content on screen当它必须更新屏幕上的内容时,您将必须手动通知乌龟
turtle.update()
This way you can get all at once - without delay这样你就可以一次得到所有 - 没有延迟
import turtle
turtle.tracer(False) # stop animation and don't update content on screen
wn = turtle.Screen()
sasha = turtle.Turtle()
length = 12
for i in range(65):
sasha.forward(length)
sasha.right(120)
length = length + 10
turtle.update() # update content on screen
turtle.done()
Doc: turtle.tracer() , turtle.update()文档: turtle.tracer() , turtle.update()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.