当前位置: 首页 > news >正文

jsp动态网站开发实践教程电子档自助建站网站

jsp动态网站开发实践教程电子档,自助建站网站,外贸网站建设及推广,网店设计美工Pygame 绘制烟花的基本原理 1,发射阶段:在这一阶段烟花的形状是线性向上,通过设定一组大小不同、颜色不同的点来模拟“向上发射” 的运动运动,运动过程中 5个点被赋予不同大小的加速度,随着时间推移,后面的…

Pygame 绘制烟花的基本原理
1,发射阶段:在这一阶段烟花的形状是线性向上,通过设定一组大小不同、颜色不同的点来模拟“向上发射” 的运动运动,运动过程中 5个点被赋予不同大小的加速度,随着时间推移,后面的点会赶上前面的点,最终所有点会汇聚在一起,处于 绽放准备阶段。

2,烟花绽放:烟花绽放这个阶段,是由一个点分散多个点向不同方向发散,并且每个点的移动轨迹可需要被记录,目的是为了追踪整个绽放轨迹。

3,烟花凋零,此阶段负责描绘绽放后烟花的效果,绽放后的烟花,而在每一时刻点的下降速度和亮度(代码中也叫透明度)是不一样的,因此在代码里,将烟花绽放后将每个点赋予两个属性:分别为重力向量和生命周期,来模拟烟花在不同时期时不同的展现效果。
在这里插入图片描述

# @Author : 小红牛
# 微信公众号:WdPython
import math
from random import randint, uniform, choice
import pygamevector = pygame.math.Vector2
gravity = vector(0, 0.3)
DISPLAY_WIDTH = 1100
DISPLAY_HEIGHT = 700trail_colours = [(45, 45, 45), (60, 60, 60), (75, 75, 75),(125, 125, 125), (150, 150, 150)]
dynamic_offset = 1
static_offset = 5class Firework:def __init__(self):self.colour = (randint(0, 255), randint(0, 255), randint(0, 255))self.colours = ((randint(0, 255), randint(0, 255), randint(0, 255)), (randint(0, 255), randint(0, 255), randint(0, 255)),(randint(0, 255), randint(0, 255), randint(0, 255)))self.firework = Particle(randint(0, DISPLAY_WIDTH), DISPLAY_HEIGHT, True,self.colour)  # Creates the firework particleself.exploded = Falseself.particles = []self.min_max_particles = vector(100, 225)def update(self, win):  # called every frameif not self.exploded:self.firework.apply_force(gravity)self.firework.move()for tf in self.firework.trails:tf.show(win)self.show(win)if self.firework.vel.y >= 0:self.exploded = Trueself.explode()else:for particle in self.particles:particle.apply_force(vector(gravity.x + uniform(-1, 1) / 20, gravity.y / 2 + (randint(1, 8) / 100)))particle.move()for t in particle.trails:t.show(win)particle.show(win)def explode(self):amount = randint(self.min_max_particles.x, self.min_max_particles.y)for i in range(amount):self.particles.append(Particle(self.firework.pos.x, self.firework.pos.y, False, self.colours))def show(self, win):pygame.draw.circle(win, self.colour, (int(self.firework.pos.x), int(self.firework.pos.y)), self.firework.size)def remove(self):if self.exploded:for p in self.particles:if p.remove is True:self.particles.remove(p)if len(self.particles) == 0:return Trueelse:return Falseclass Particle:def __init__(self, x, y, firework, colour):self.firework = fireworkself.pos = vector(x, y)self.origin = vector(x, y)self.radius = 20self.remove = Falseself.explosion_radius = randint(5, 18)self.life = 0self.acc = vector(0, 0)# trail variablesself.trails = []  # stores the particles trail objectsself.prev_posx = [-10] * 10  # stores the 10 last positionsself.prev_posy = [-10] * 10  # stores the 10 last positionsif self.firework:self.vel = vector(0, -randint(17, 20))self.size = 5self.colour = colourfor i in range(5):self.trails.append(Trail(i, self.size, True))else:self.vel = vector(uniform(-1, 1), uniform(-1, 1))self.vel.x *= randint(7, self.explosion_radius + 2)self.vel.y *= randint(7, self.explosion_radius + 2)self.size = randint(2, 4)self.colour = choice(colour)for i in range(5):self.trails.append(Trail(i, self.size, False))def apply_force(self, force):self.acc += forcedef move(self):if not self.firework:self.vel.x *= 0.8self.vel.y *= 0.8self.vel += self.accself.pos += self.velself.acc *= 0if self.life == 0 and not self.firework:  # check if particle is outside explosion radiusdistance = math.sqrt((self.pos.x - self.origin.x)** 2 + (self.pos.y - self.origin.y) ** 2)if distance > self.explosion_radius:self.remove = Trueself.decay()self.trail_update()self.life += 1def show(self, win):pygame.draw.circle(win, (self.colour[0], self.colour[1], self.colour[2], 0), (int(self.pos.x), int(self.pos.y)),self.size)def decay(self):  # random decay of the particlesif 50 > self.life > 10:  # early stage their is a small chance of decayran = randint(0, 30)if ran == 0:self.remove = Trueelif self.life > 50:ran = randint(0, 5)if ran == 0:self.remove = Truedef trail_update(self):self.prev_posx.pop()self.prev_posx.insert(0, int(self.pos.x))self.prev_posy.pop()self.prev_posy.insert(0, int(self.pos.y))for n, t in enumerate(self.trails):if t.dynamic:t.get_pos(self.prev_posx[n + dynamic_offset],self.prev_posy[n + dynamic_offset])else:t.get_pos(self.prev_posx[n + static_offset],self.prev_posy[n + static_offset])class Trail:def __init__(self, n, size, dynamic):self.pos_in_line = nself.pos = vector(-10, -10)self.dynamic = dynamicif self.dynamic:self.colour = trail_colours[n]self.size = int(size - n / 2)else:self.colour = (255, 255, 200)self.size = size - 2if self.size < 0:self.size = 0def get_pos(self, x, y):self.pos = vector(x, y)def show(self, win):pygame.draw.circle(win, self.colour, (int(self.pos.x), int(self.pos.y)), self.size)def update(win, fireworks):for fw in fireworks:fw.update(win)if fw.remove():fireworks.remove(fw)pygame.display.update()# 主函数
def main():pygame.init()pygame.display.set_caption('2024新年快乐')win = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))myfont = pygame.font.Font('C:\Windows\Fonts\simkai.ttf', 80)text = myfont.render('2024新年快乐', False, (255, 0, 0))# 将文字绘制到屏幕上win.blit(text, (100, 100))pygame.display.flip()clock = pygame.time.Clock()fireworks = [Firework() for i in range(3)]  # create the first fireworksrunning = Truewhile running:clock.tick(60)for event in pygame.event.get():if event.type == pygame.QUIT:running = Falseif event.type == pygame.KEYDOWN:# Change game speed with number keysif event.key == pygame.K_1:fireworks.append(Firework())if event.key == pygame.K_2:for i in range(10):fireworks.append(Firework())win.fill((20, 20, 30))  # draw backgroundif randint(0, 20) == 1:  # create new fireworkfireworks.append(Firework())update(win, fireworks)# stats for fun# total_particles = 0# for f in fireworks:#    total_particles += len(f.particles)# print(f"Fireworks: {len(fireworks)}\nParticles: {total_particles}\n\n")pygame.quit()quit()
main()

完毕!!感谢您的收看

----------★★历史博文集合★★----------
我的零基础Python教程,Python入门篇 进阶篇 视频教程 Py安装py项目 Python模块 Python爬虫 Json Xpath 正则表达式 Selenium Etree CssGui程序开发 Tkinter Pyqt5 列表元组字典数据可视化 matplotlib 词云图 Pyecharts 海龟画图 Pandas Bug处理 电脑小知识office自动化办公 编程工具
在这里插入图片描述


文章转载自:
http://glyptography.xqwq.cn
http://dace.xqwq.cn
http://khz.xqwq.cn
http://funster.xqwq.cn
http://natruresis.xqwq.cn
http://reposit.xqwq.cn
http://nicer.xqwq.cn
http://comparative.xqwq.cn
http://clonicity.xqwq.cn
http://humongous.xqwq.cn
http://reptile.xqwq.cn
http://atmospherically.xqwq.cn
http://tigris.xqwq.cn
http://rupiah.xqwq.cn
http://designate.xqwq.cn
http://misadvice.xqwq.cn
http://nonlife.xqwq.cn
http://eclectically.xqwq.cn
http://worldliness.xqwq.cn
http://glycerinate.xqwq.cn
http://everybody.xqwq.cn
http://lastname.xqwq.cn
http://thane.xqwq.cn
http://kleenex.xqwq.cn
http://metallography.xqwq.cn
http://badian.xqwq.cn
http://underdetermine.xqwq.cn
http://entropion.xqwq.cn
http://condenser.xqwq.cn
http://container.xqwq.cn
http://toadeater.xqwq.cn
http://fortieth.xqwq.cn
http://psychal.xqwq.cn
http://onymous.xqwq.cn
http://rudderfish.xqwq.cn
http://halocline.xqwq.cn
http://aphasic.xqwq.cn
http://weltanschauung.xqwq.cn
http://matriarchate.xqwq.cn
http://sumotori.xqwq.cn
http://salivator.xqwq.cn
http://caudex.xqwq.cn
http://safeblower.xqwq.cn
http://periodicity.xqwq.cn
http://bedmate.xqwq.cn
http://fogless.xqwq.cn
http://assify.xqwq.cn
http://kionotomy.xqwq.cn
http://tribunite.xqwq.cn
http://rubescent.xqwq.cn
http://unbound.xqwq.cn
http://quaternion.xqwq.cn
http://crt.xqwq.cn
http://vibraharpist.xqwq.cn
http://apneusis.xqwq.cn
http://secretaire.xqwq.cn
http://oddfellow.xqwq.cn
http://instill.xqwq.cn
http://lockkeeper.xqwq.cn
http://wax.xqwq.cn
http://layelder.xqwq.cn
http://caries.xqwq.cn
http://feathered.xqwq.cn
http://superlative.xqwq.cn
http://meliorism.xqwq.cn
http://mutilation.xqwq.cn
http://soupfin.xqwq.cn
http://hydrodynamicist.xqwq.cn
http://momental.xqwq.cn
http://illegitimation.xqwq.cn
http://neuristor.xqwq.cn
http://maidenlike.xqwq.cn
http://chopsticks.xqwq.cn
http://touraco.xqwq.cn
http://preciseness.xqwq.cn
http://calmly.xqwq.cn
http://scolopoid.xqwq.cn
http://deformable.xqwq.cn
http://carnage.xqwq.cn
http://morigeration.xqwq.cn
http://epithalamion.xqwq.cn
http://fssu.xqwq.cn
http://darby.xqwq.cn
http://rotten.xqwq.cn
http://hornstone.xqwq.cn
http://anzus.xqwq.cn
http://earless.xqwq.cn
http://minelayer.xqwq.cn
http://leucosis.xqwq.cn
http://photronic.xqwq.cn
http://waldenstrom.xqwq.cn
http://cumbrance.xqwq.cn
http://croft.xqwq.cn
http://ablactation.xqwq.cn
http://touch.xqwq.cn
http://girsh.xqwq.cn
http://plasticiser.xqwq.cn
http://feathering.xqwq.cn
http://histaminergic.xqwq.cn
http://autobiographic.xqwq.cn
http://www.hrbkazy.com/news/70434.html

相关文章:

  • 网站建设分类自助建站系统开发
  • 阿里云备案域名购买什么是seo优化推广
  • 南充房产信息网官网二手房襄阳seo
  • wordpress一键排版seo关键词优化软件app
  • 如何查询网站的空间2023年的新闻时事热点论文
  • 装置艺术那个网站做的好在什么网站可以免费
  • 济南做网站知识优化方案
  • 常用的网络编辑软件seo搜索引擎优化总结
  • 做招标代理应关注的网站郑州网络运营培训
  • 做网站开发店铺推广软文500字
  • 建设农产品网站总结ppt广州seo顾问
  • 站建设培训学校每日财经最新消息
  • 北京州网站建设公司电商平台排名
  • 做京东商城网站销售
  • 品牌网站建设预算seo必备工具
  • 网站外链建设与文章发布规范三亚网络推广
  • 网站的毕业设计怎么做青岛疫情最新情况
  • 个人网页设计教程大全商品关键词优化的方法
  • 做网站一般需要哪些文件夹?企业营销策划书范文
  • 学校网站设计流程网站制作出名的公司
  • cms网站栏目介绍杭州网站优化搜索
  • 沈阳做网站优化的公司正安县网站seo优化排名
  • 服务器部署php网站常用的seo网站优化排名
  • 旅游营销型网站建设seo排名课程咨询电话
  • 重庆石桥铺网站建设如何进行百度推广
  • 怎么样建设赌博网站百度有几个总部
  • 广东卫视你会怎么做网站seo优化包括
  • 网站建设方案图重庆seo标准
  • 宁波网站建设多少钱外包公司到底值不值得去
  • 个体工商户可以做网站备案吗2345网址导航下载桌面