pygame实现星际穿越粒子动画
刚接触pygame,写个流星练练手
import randomimport pygame# 流星类
class Star(object):"""用于指定流星的位置,移动向量,星尾长度"""def __init__(self, point, screen, all_speed):self.startx = point[0]self.starty = point[1]screen_rect = screen.get_rect() # 获得屏幕矩形self.speed_x = (self.startx - screen_rect.centerx) / 25 * all_speed[speed_index] # 水平方向速度设置self.speed_y = (self.starty - screen_rect.centery) / 25 * all_speed[speed_index] # 竖直方向速度设置self.end_x = self.startx + self.speed_x * 5 # 星尾self.end_y = self.starty + self.speed_y * 5 # 星尾self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))def blitme(self):pygame.draw.aaline(screen, self.color, (star.startx, star.starty), (star.end_x, star.end_y), 100) # 绘制流星轨迹# 屏幕上流星检测
def on_screen(point): if 0 < point[0] < 1600 and 0 < point[1] < 900 and not(point[0] == 800 and point[1] == 450):return point# 初始化设置
pygame.init()screen = pygame.display.set_mode((1600, 900))
screen_rect = screen.get_rect()
points = [] # 用于存储流星的点集
for i in range(10): # 生成十颗流星point = [random.randint(600, 1000), random.randint(250, 650)]points.append(point)# 全局速度(加速和反向加速)
n = 0
all_speed = []
speed_index = 0 # 全局速度列表索引
while n < 1000:i = n/100all_speed.append(i) # 全局速度n += 1# 主循环
while True:for event in pygame.event.get():if event.type== pygame.QUIT:pygame.quit()exit()screen.fill(0)pygame.time.Clock().tick(96)if speed_index < 999:speed_index += 1 # 速度加快else:speed_index = 0all_speed.reverse() # 反向加速# 新增一颗流星point1 = [random.randint(600, 1000), random.randint(250, 650)]points.append(point1)# 画流星for point in points:star = Star(point, screen, all_speed)star.blitme()# 流星移动point[0] = star.startx + star.speed_x # 崩溃的电脑 point[1] = star.starty + star.speed_y # 崩溃的电脑points = list(filter(on_screen, points)) # 内存控制pygame.display.update()"""
1、随机坐标的生成和存储
2、流星类
3、流星速度控制
4、星尾长度
5、帧率控制
6、内存管理
7、全局速度控制
"""
pygame实现星际穿越粒子动画相关推荐
- 天体物理学-星际穿越
转载自: http://www.cnblogs.com/yangpf/p/4148488.html 确实非常喜欢这样的文章,简单的说明白了很多有意思的科学史.天体物理学啊天体物理学.. 以下是原文 本 ...
- python实现“粒子动画”
python讨论qq群:996113038 导语: 最近浏览网页的时候经常看见一些炫酷的网页,其中影响最深刻的就是粒子动画.每次用鼠标点击一个位置.就会有相应的点和线的变化.虽然是非常简单的几何图形. ...
- canvas学习之粒子动画
项目地址:http://pan.baidu.com/s/1ccTptc 粒子动画意思就是把一个图片粒子画,然后使用粒子作出动画效果,主要两个问题:一个图片如何粒子化,这里面我们使用canvas的get ...
- 「PKUSC2018」星际穿越 (70分做法)
5371: [Pkusc2018]星际穿越 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 27 Solved: 11 [Submit][Statu ...
- canvas粒子动画
2019独角兽企业重金招聘Python工程师标准>>> 周末在家玩了一下canvas粒子动画,先看看效果,用的图是我们微众银行的干爹'qq',先看看效果 ##1.获取图片信息 ### ...
- vuejs粒子动画特效 npm安装插件vue-particles(particles.js) - 代码篇
文章目录 1. npm 安装插件`vue-particles` 2. 效果图: 3. 代码截图: 4. 代码示下: 5. 附件 · 文章阅读: 1. npm 安装插件vue-particles npm ...
- 惊艳的HTML5粒子动画特效
转自:http://geek.csdn.net/news/detail/201487?ref=myread HTML5确实非常强大,很多时候我们可以利用HTML5中的新技术实现非常炫酷的粒子动画效果, ...
- 带着canvas去流浪系列之九 粒子动画
[摘要] canvas实现粒子动画 示例代码托管在:http://www.github.com/dashnowords/blogs 一. 粒子特效 粒子特效一般指密集点阵效果,它并不是canvas独有 ...
- WPF特效-粒子动画
原文:WPF特效-粒子动画 WPF实现泡泡龙小游戏效果. /// -Ball to Ball Collision - Detection and Handling /// http://sta ...
最新文章
- 大数据学习01——配置虚拟机节点相关网络
- JQuery操作checkbox、radio
- ASP.NET Core中间件(Middleware)实现WCF SOAP服务端解析
- 重学java基础第三课:学习方法和课程概述
- WPF中制作立体效果的文字或LOGO图形
- webform窗体怎么实现session唯一标识_微信小程序用户登录和登录态维护的实现_javascript技巧...
- cuda合并访问的要求_【CUDA 基础】4.3 内存访问模式
- 将mysql数据库中的图片读出来的_MySQL存入图片+Qt读入读出数据库中的图片
- replace vfp_VFP字符串替换函数CHRTRAN()使用方法
- CocosCreator之场景编辑器介绍
- matlab求两向量夹角_高考数学一轮复习,利用空间向量求夹角和距离,各考点聚焦突破...
- 【QT】自定义Toast消息提示
- 最常见的Web网站攻击手段
- 相机标定实验过程注意问题及总结
- lisp不是函授型语言_lisp函数大全详解
- 垃圾回收的主要区域是堆,那方法区会回收吗?
- 和sar比起来,其他Linux命令都是猹---ing
- python图形化编程wx_慢步python,图形用户界面库:wxPython库 初体验,先建一个窗体...
- 计算机联锁的英语文献,计算机联锁系统毕业论文中英文资料外文翻译文献
- aspen模拟蒸发器_用Aspen Plus设计蒸发器例题