位于龟没有动画 - Python的3​​.4? [英] Set no animation in Turtle - Python 3.4?

查看:223
本文介绍了位于龟没有动画 - Python的3​​.4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下code创建了一个分形树。我想提请它尽可能快 - 我不希望发生任何动画,否则就需要很长的时间来绘制。在早期版本的蟒蛇,这是与turtle.speed(0)实现的,如下图所示。这并不在Python 3.4工作

The code below creates a fractal tree. I want to draw it as quick as possible -- I don't want any animation to occur, otherwise it takes a long time to draw. In earlier versions of python, this is achieved with turtle.speed(0), as shown below. This doesn't work in python 3.4

import turtle
import random
red = 125
green = 70
blue = 38        
pen = 10
def tree(branchLen, t, red, green, blue, pen):
    if branchLen > 3:
        pen = pen*0.8
        t.pensize(pen)
        red = red - 15
        green = green + 8
    if branchLen > 5:
        angle = random.randrange(10, 70)
        angleTwo = 0.50*angle
        sub = (0.8*(random.randrange(1,24)))
        t.forward(branchLen)
        t.right(angleTwo)
        tree(branchLen-sub,t, red, green, blue, pen)
        t.left(angle)
        tree(branchLen-sub, t, red, green, blue, pen)
        t.right(angleTwo)
        t.backward(branchLen)

def main():
    t = turtle.Turtle()
    t.hideturtle()
    t.speed(0)
    myWin = turtle.Screen()
    t.left(90)
    t.up()
    t.backward(170)
    t.down()
    tree(random.randrange(40,47),t,red,green,blue, pen)
    myWin.exitonclick()

main()

看来速度模块没有在3.4做任何事情。不管使用什么号码(0-10),它总是以相同的速度,并且不显示错误 - 这意味着它仍然动画。

It seems the speed module doesn't do anything in 3.4. No matter what number (0-10) used, it's always the same speed and doesn't display an error -- Meaning it still animates.

我怎样才能实现与龟没有动画在Python 3.4? http://interactivepython.org/runestone/static/pythonds/Recursion/graphical.html 这是一个很好的地方跑在Python 2 code,只需更换窗户codeS与我的。

How can I achieve no animation with turtle in python 3.4? http://interactivepython.org/runestone/static/pythonds/Recursion/graphical.html This is a good place to run the code in Python 2, just replace one of the windows codes with mine.

推荐答案

我想使用的 turtle.tracer(假),因为它忽略了动画将是有益的。

I think using turtle.tracer(False) would be useful as it ignores the animation.

这篇关于位于龟没有动画 - Python的3​​.4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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