闪亮的五角星

"""python动画闪亮的五角星,本程序为讲解模块化与类而设计。在point模块中有Point类,用来代表一个坐标点。相信读者根据阅读程序能自己写Point类写出来,这就做为一个小作业吧。这个Point类真的很简单的,没必要贴出来了。
"""

from turtle import *
from point import *
from random import randint

class Star(Turtle):
    def __init__(self,images,pos):
        Turtle.__init__(self,visible=False)
        self.penup()
        self.images = images
        self.index = 0
        self.goto(pos.x,pos.y)
        self.twinkle()
        self.st()
        
    def twinkle(self):
        """闪烁方法"""
        self.index = 1 - self.index
        self.shape(self.images[self.index])
        self.screen.ontimer(self.twinkle,randint(300,800))


if __name__ == "__main__":

    screen = Screen()
    screen.setup(800,600)
    screen.title("闪亮的五角星by李兴球")
    screen.delay(0)
    screen.bgpic("bg2.png")
    screen.addshape("star1.gif")
    screen.addshape("star2.gif")
    images = ["star1.gif","star2.gif"]

    point_list = []
    t = Turtle(visible=False)
    t.penup()
    t.goto(-100,0)
    for i in range(5):
        for j in range(20):
            x,y = t.position()
            point_list.append(Point(x,y))    # 把点坐标添加到点列表
            t.fd(10)
        t.rt(144)
            
    while point_list:
        p = point_list.pop()
        Star(images,p) 
        

    screen.mainloop()
    
    

python动画闪亮的五角星