Thursday, December 4, 2014


Round Dance





from turtle import *

def stop():
    global running
    running = False

def main():
    global running
    clearscreen()    
    bgcolor ("white") 
    tracer(False)
    shape("circle")  
    f =   0.793402
    phi = 9.064678
    s = 3
    c = 1
    # create compound shape
    sh = Shape("compound")
    for i in range(10):
        shapesize(s)
        p =get_shapepoly()
        s *= f
        c *= f
        tilt(phi)
        sh.addcomponent(p, (c, 0.25, 1-c), "black")
    register_shape("multitri", sh)
    # create dancers
    shapesize(1)
    shape("multitri")
    been ()
    setpos (0, -200)
    dancers = []
    for i in range(180):
        f (9)
        tilt(-6)
        pl (2)
        update()
        if i % 18 == 0:
            dancers.append(clone())
    home()
    # dance
    running = True
    onkeypress(stop)
    listen()
    cs = 1
    while running:
        a = -4
        for dancer in dancers:
            dancer.fd(9)
            dancer.lt (2)
            dancer.tilt(ta)
            ta = -4 if ta > 0 else 2
        if cs < 180:
            right(4)
            shapesize(cs)
            cs *= 1.005
        update()
    return "DONE!"

if __name__=='__main__':
    print(main())
    mainloop()

1 comment:

  1. Good,

    one suggestion:
    go to https://gist.github.com/
    learn about posting python codes there
    and using embeded html here,
    then the code will look better.

    ReplyDelete