Commit 852f3cc0 authored by Benjamin Peterson's avatar Benjamin Peterson

fix demo/doc eol

parent 69150c77
This diff is collapsed.
""" turtle-example-suite: """ turtle-example-suite:
tdemo_round_dance.py tdemo_round_dance.py
(Needs version 1.1 of the turtle module that (Needs version 1.1 of the turtle module that
comes with Python 3.1) comes with Python 3.1)
Dancing turtles have a compound shape Dancing turtles have a compound shape
consisting of a series of triangles of consisting of a series of triangles of
decreasing size. decreasing size.
Turtles march along a circle while rotating Turtles march along a circle while rotating
pairwise in opposite direction, with one pairwise in opposite direction, with one
exception. Does that breaking of symmetry exception. Does that breaking of symmetry
enhance the attractiveness of the example? enhance the attractiveness of the example?
Press any key to stop the animation. Press any key to stop the animation.
Technically: demonstrates use of compound Technically: demonstrates use of compound
shapes, transformation of shapes as well as shapes, transformation of shapes as well as
cloning turtles. The animation is cloning turtles. The animation is
controlled through update(). controlled through update().
""" """
from turtle import * from turtle import *
def stop(): def stop():
global running global running
running = False running = False
def main(): def main():
global running global running
clearscreen() clearscreen()
bgcolor("gray10") bgcolor("gray10")
tracer(False) tracer(False)
shape("triangle") shape("triangle")
f = 0.793402 f = 0.793402
phi = 9.064678 phi = 9.064678
s = 5 s = 5
c = 1 c = 1
# create compound shape # create compound shape
sh = Shape("compound") sh = Shape("compound")
for i in range(10): for i in range(10):
shapesize(s) shapesize(s)
p =get_shapepoly() p =get_shapepoly()
s *= f s *= f
c *= f c *= f
tilt(-phi) tilt(-phi)
sh.addcomponent(p, (c, 0.25, 1-c), "black") sh.addcomponent(p, (c, 0.25, 1-c), "black")
register_shape("multitri", sh) register_shape("multitri", sh)
# create dancers # create dancers
shapesize(1) shapesize(1)
shape("multitri") shape("multitri")
pu() pu()
setpos(0, -200) setpos(0, -200)
dancers = [] dancers = []
for i in range(180): for i in range(180):
fd(7) fd(7)
tilt(-4) tilt(-4)
lt(2) lt(2)
update() update()
if i % 12 == 0: if i % 12 == 0:
dancers.append(clone()) dancers.append(clone())
home() home()
# dance # dance
running = True running = True
onkeypress(stop) onkeypress(stop)
listen() listen()
cs = 1 cs = 1
while running: while running:
ta = -4 ta = -4
for dancer in dancers: for dancer in dancers:
dancer.fd(7) dancer.fd(7)
dancer.lt(2) dancer.lt(2)
dancer.tilt(ta) dancer.tilt(ta)
ta = -4 if ta > 0 else 2 ta = -4 if ta > 0 else 2
if cs < 180: if cs < 180:
right(4) right(4)
shapesize(cs) shapesize(cs)
cs *= 1.005 cs *= 1.005
update() update()
return "DONE!" return "DONE!"
if __name__=='__main__': if __name__=='__main__':
print(main()) print(main())
mainloop() mainloop()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment