[Edu-sig] Use? Abuse? Amusement? Amendments?

Gregor Lingl glingl@aon.at
Wed, 31 Jul 2002 23:53:03 +0200


This is a multi-part message in MIME format.
--------------070104060008060808070206
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi!
If you, incidentally, are going to have a coffee-break,
please, run the code of the attachment.
Your opinion?
Gregor


--------------070104060008060808070206
Content-Type: text/plain;
 name="trees.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="trees.py"

from __future__ import generators
from turtle import *
        
def ttree(t,l):
    if l > 12.0:
        t.forward(l)
        yield 1
        t.left(25)
        for x in ttree(t, l * 0.65 ):
            yield x
        t.right(60)
        yield 1
        for x in ttree(t, l * 0.52 ):
            yield x
        t.left(35)
        t.backward(l)
        yield 1

turtles = (leonardo, raphael, donatello) = (Pen(), Pen(), Pen())
for turtle in turtles:
    turtle.left(90)
    turtle.up()

leonardo.goto(-100,-100)
leonardo.color("red")
raphael.goto( 0, -100)
raphael.color("green")
donatello.goto(100,-100)
donatello.color("orange")

for turtle in turtles:
    turtle.down()
    turtle.width(3)

ltree = ttree(leonardo,79.0)
rtree = ttree(raphael, 100.0)
dtree = ttree(donatello, 66.0)

done = 0
while done < 3:
    done = 0
    for tree in (ltree, rtree, dtree):
        try:
            tree.next()
        except:
            done += 1

leonardo.up()
leonardo.goto(-140,-135)
leonardo.write("HOW CAN THIS BE DONE WITHOUT GENERATORS?")

raw_input("Press Enter!")


--------------070104060008060808070206--