以下是部分代码预览:
"""python动画闪亮的五角星,本程序为讲解模块化与类而设计。在point模块中有Point类,用来代表一个坐标点。
"""
from turtle 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()
如需要查看完整代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

