[英]How do I make a turtle 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
你可以使用speed()
函數,你增加的越多,你增加的值就越慢。
例如,您可以像sasha.speed(0
) 這樣使用它。
注意:
speed(0)
是最快的,因為筆不會繪制。
在這里查看更多信息
您可以使用speed()
來改變烏龜的速度 - 就像在其他答案中一樣 - 但你也可以關閉動畫
turtle.tracer(False)
當它必須更新屏幕上的內容時,您將必須手動通知烏龜
turtle.update()
這樣你就可以一次得到所有 - 沒有延遲
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.