当我们有 turtle.tracer(0) 时,是否需要设置 `turtle.speed(0)` [英] Is setting `turtle.speed(0)` necessary when we have turtle.tracer(0)

查看:82
本文介绍了当我们有 turtle.tracer(0) 时,是否需要设置 `turtle.speed(0)`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有区别:

import turtle
turtle.tracer(0)
turtle.speed(0)
while True:
    turtle.goto(turtle.xcor()+1)
    turtle.update()

还有:

import turtle
turtle.tracer(0)
while True:
    turtle.goto(turtle.xcor()+1)
    turtle.update()

我听说设置 turtle.speed(0) 可以让事情更快,但如果是这样,我看不出有什么区别.

I've heard that setting turtle.speed(0) make things faster, but if so, I don't see any difference.

推荐答案

根据:https://www.eg.bucknell.edu/~hyde/Python3/TurtleDirections.html

tracer() 方法:

  • 可用于加速复杂图形的绘制.

  • Can be used to accelerate the drawing of complex graphics.

关闭海龟会使海龟消失并加快绘制速度.

Turning the turtle off makes the turtle disappear and makes drawing MUCH faster.

以及官方文档https://docs.python.org/2/library/turtle.html#turtle.speed 说:

  • fastest": 0 # 用于设置海龟速度

结论:我认为可以这样说:

CONCLUSION: I think it is fair to say that:

如果您正在处理非常复杂的图形,并且想要速度,请同时使用两者,并且在复杂图形中您应该会看到某种差异,因为它们都可以加速乌龟

如果你在做简单的图形,使用两者的速度不会比做复杂的速度明显,所以没有必要同时使用两者而只使用,例如:turtle.speed(0) 根据官方文档:https://docs.python.org/2/library/turtle.html#turtle.tracer tracer() 已在新版本的海龟模块中弃用.

If you are doing simple graphics, the speed from using both will not as noticeable than if you did a complex one, so it would not be necessary to use both but only use, for example: turtle.speed(0) As according to the official documentation: https://docs.python.org/2/library/turtle.html#turtle.tracer tracer() has been deprecated in newer versions of the turtle module.

所以我建议先改变速度,然后如果你需要更快的性能改变追踪器.或者您可以禁用追踪器,因为您不想显示海龟动画,这真的取决于您,但我希望我能指导您.

So I would suggest changing the speed first, and then if you need faster performance change the tracer. Or you can just disable the tracer because you do not want the turtle animation to show, really it is up to you, but I hope I could have guided you.

这篇关于当我们有 turtle.tracer(0) 时,是否需要设置 `turtle.speed(0)`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆