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

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()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亦悰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值