当前位置:   article > 正文

用python的turtle模块制作一个有立体效果发射光芒的五角星沿着圆周匀速运动的动画。_python绘制立体五角形

python绘制立体五角形

import turtle as tl

from math import sin

from math import pi

fill_color= {0:'purple', 1:'blueviolet'}

colors=["mediumslateblue","mediumpurple","indigo"]

R = 80

l1 = int(R*sin(pi/10)/sin(pi*126/180))

l2 = int(R*sin(pi/5)/sin(pi*126/180))

distanceList = [l1, l2, R]

angleList = [54, 162, 180]

myAngle= 0

myCounter = 0

counter = 0

def Tick():

    global myCounter

    global counter

    global myAngle

    tl.tracer(False)

    oneDraw(myCounter,counter,myAngle)

    tl.tracer(True)

    myCounter = (myCounter + 1) % 3

    counter = (counter + 1) % 10

    myAngle=(myAngle+18)%360

    tl.ontimer(Tick,100)

def oneDraw(counter,stepCounter,myAngle):

    global distanceList, angleList

    tl.reset()

    for k in range(0,3):

        tl.pencolor(colors[3-(k+1)])

        for i in range(73):

            tl.penup()

            tl.home()

            tl.left(myAngle)

            tl.forward(200)

            tl.right(myAngle)

            tl.right(5*i)

            tl.forward(R/2+k*R/4+counter*R/12)

            tl.pendown()

            tl.forward(R*sin((pi/2)*((i%5+1)/5))/10)

    tl.penup()

    tl.home()

    tl.left(myAngle)

    tl.forward(200)

    tl.right(myAngle)

    tl.right(stepCounter*36)

    tl.left(126)

    for i in range(10):

        tl.fillcolor(fill_color.get(i%2))

        tl.begin_fill()

        for j in range(3):

            tl.forward(distanceList[j])

            tl.right(angleList[j])

        tl.end_fill()

        distanceList = list(reversed(distanceList))

        angleList = list((angleList[1], angleList[0], angleList[2]))   

def main():

    Tick()

    tl.mainloop()

main()

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号