python tracer(false)_位于龟没有动画 - 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()

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.

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.

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值