admin管理员组文章数量:1794759
Python流星雨
前言
用Python画场流星雨看看,源码见文末公众号哈。
流星类def __init__(self): self.r = ra.randint(50,100) self.t = ra.randint(1,3) self.x = ra.randint(-2000,1000) #流星的横坐标 self.y = ra.randint(0,500) #流星的纵坐标 self.speed = ra.randint(5,10) #流星移动速度 self.color = ra.choice(colors) #流星的颜色 self.outline = 1 #流星的大小
画流星def star(self): #画流星函数 t.pensize(self.outline) #流星的大小 t.penup() #提笔 t.goto(self.x,self.y) #随机位置 t.pendown() #落笔 t.color(self.color) t.begin_fill() t.fillcolor(self.color) t.setheading(-30) t.right(self.t) t.forward(self.r) t.left(self.t) t.circle(self.r*math.sin(math.radians(self.t)),180) t.left(self.t) t.forward(self.r) t.end_fill()
移动函数def move(self): #流星移动函数 if self.y >= -500: #当流星还在画布中时 self.y -= self.speed #设置上下移动速度 self.x += 2*self.speed #设置左右移动速度 else: self.r = ra.randint(50,100) self.t = ra.randint(1,3) self.x = ra.randint(-2000,1000) self.y = 500 self.speed = ra.randint(5,10) self.color = ra.choice(colors) self.outline = 1
版权声明:本文标题:Python流星雨 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686987435a125798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论