Back to index

python3.2  3.2.2
Functions
turtledemo.round_dance Namespace Reference

Functions

def stop
def main

Detailed Description

turtle-example-suite:

 tdemo_round_dance.py

(Needs version 1.1 of the turtle module that
comes with Python 3.1)

Dancing turtles have a compound shape
consisting of a series of triangles of
decreasing size.

Turtles march along a circle while rotating
pairwise in opposite direction, with one
exception. Does that breaking of symmetry
enhance the attractiveness of the example?

Press any key to stop the animation.

Technically: demonstrates use of compound
shapes, transformation of shapes as well as
cloning turtles. The animation is
controlled through update().

Function Documentation

Definition at line 31 of file round_dance.py.

00031 
00032 def main():
00033     global running
00034     clearscreen()
00035     bgcolor("gray10")
00036     tracer(False)
00037     shape("triangle")
00038     f =   0.793402
00039     phi = 9.064678
00040     s = 5
00041     c = 1
00042     # create compound shape
00043     sh = Shape("compound")
00044     for i in range(10):
00045         shapesize(s)
00046         p =get_shapepoly()
00047         s *= f
00048         c *= f
00049         tilt(-phi)
00050         sh.addcomponent(p, (c, 0.25, 1-c), "black")
00051     register_shape("multitri", sh)
00052     # create dancers
00053     shapesize(1)
00054     shape("multitri")
00055     pu()
00056     setpos(0, -200)
00057     dancers = []
00058     for i in range(180):
00059         fd(7)
00060         tilt(-4)
00061         lt(2)
00062         update()
00063         if i % 12 == 0:
00064             dancers.append(clone())
00065     home()
00066     # dance
00067     running = True
00068     onkeypress(stop)
00069     listen()
00070     cs = 1
00071     while running:
00072         ta = -4
00073         for dancer in dancers:
00074             dancer.fd(7)
00075             dancer.lt(2)
00076             dancer.tilt(ta)
00077             ta = -4 if ta > 0 else 2
00078         if cs < 180:
00079             right(4)
00080             shapesize(cs)
00081             cs *= 1.005
00082         update()
00083     return "DONE!"

Here is the call graph for this function:

Definition at line 27 of file round_dance.py.

00027 
00028 def stop():
00029     global running
00030     running = False