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

网站建设预算表样本怎么优化网站内容

网站建设预算表样本,怎么优化网站内容,软件下载网站怎么做,购物网站app制作欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 新年的钟声即将敲响,为了庆祝这个喜庆的时刻,我们可以用 Python 编写一个炫彩夺目的烟花盛典。本文将详细介绍如何使用 Pygame 库创建一个令人惊叹的烟花效果。 一、效果图: 二…

        欢迎来到英杰社区icon-default.png?t=N7T8https://bbs.csdn.net/topics/617804998     

   新年的钟声即将敲响,为了庆祝这个喜庆的时刻,我们可以用 Python 编写一个炫彩夺目的烟花盛典。本文将详细介绍如何使用 Pygame 库创建一个令人惊叹的烟花效果。

一、效果图:

        

二、准备工作

(1)、导入必要的模块:

       代码首先导入了需要使用的模块:requests、lxml和csv。

import requests
from lxml import etree
import csv

        如果出现模块报错

c124a1693bfc457ba1f2909ee9d299fc.png

        进入控制台输入:建议使用国内镜像源

pip install 模块名称 -i https://mirrors.aliyun.com/pypi/simple

         我大致罗列了以下几种国内镜像源:

清华大学
https://pypi.tuna.tsinghua.edu.cn/simple阿里云
https://mirrors.aliyun.com/pypi/simple/豆瓣
https://pypi.douban.com/simple/ 百度云
https://mirror.baidu.com/pypi/simple/中科大
https://pypi.mirrors.ustc.edu.cn/simple/华为云
https://mirrors.huaweicloud.com/repository/pypi/simple/腾讯云
https://mirrors.cloud.tencent.com/pypi/simple/

        (2) 、定义粒子类

        接下来,我们定义一个粒子类,每个粒子具有位置、颜色、半径、角度、速度、重力和生命周期等属性。我们还为粒子类添加更新和绘制方法。

class Particle:def __init__(self, x, y, color):self.x = xself.y = yself.color = colorself.radius = 3self.angle = randint(0, 360)self.speed = randint(1, 5)self.gravity = 0.1self.life = randint(20, 25)def update(self):if self.life > 0:radian = math.radians(self.angle)self.x += self.speed * math.cos(radian)self.y -= self.speed * math.sin(radian)self.speed -= self.gravityself.life -= 1def draw(self):pygame.draw.circle(win, self.color, (int(self.x), int(self.y)), self.radius)

        (3)、定义烟花类

         接下来,我们定义一个烟花类,每个烟花具有位置、颜色、粒子列表和是否已经爆炸的属性。我们为烟花类添加爆炸和更新方法,并在绘制方法中绘制烟花本身。

 
class Firework:def __init__(self):self.x = randint(100, DISPLAY_WIDTH - 100)self.y = DISPLAY_HEIGHTself.color = (randint(0, 255), randint(0, 255), randint(0, 255))self.particles = []self.exploded = Falsedef explode(self):for _ in range(100):particle = Particle(self.x, self.y, self.color)self.particles.append(particle)def update(self):if not self.exploded:self.y -= 3if self.y <= randint(200, 400):self.explode()self.exploded = Trueelse:for particle in self.particles:particle.update()def draw(self):pygame.draw.circle(win, self.color, (int(self.x), int(self.y)), 5)

        (4)、游戏主循环

        在主循环中,我们处理退出事件,清空窗口,更新和绘制每个烟花及其粒子,移除完成的烟花和消失的粒子,并更新显示。

# 创建烟花列表
fireworks = []# 游戏主循环
running = True
clock = pygame.time.Clock()while running:clock.tick(60)for event in pygame.event.get():if event.type == pygame.QUIT:running = Falsewin.fill(BLACK)# 添加新的烟花if len(fireworks) < 10 and randint(0, 100) < 2:fireworks.append(Firework())# 更新和绘制烟花for firework in fireworks:firework.update()firework.draw()for particle in firework.particles:particle.draw()# 移除完成的烟花及消失的粒子fireworks = [firework for firework in fireworks if not firework.exploded or len(firework.particles) > 0]for firework in fireworks:firework.particles = [particle for particle in firework.particles if particle.life > 0]pygame.display.update()pygame.quit()

英杰社区icon-default.png?t=N7T8https://bbs.csdn.net/topics/617804998

三、完整代码:

        

import pygame
import math
from random import randint, choice# 初始化 Pygame
pygame.init()# 设置窗口大小和标题
DISPLAY_WIDTH = 800
DISPLAY_HEIGHT = 600
win = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
pygame.display.set_caption("烟花")# 定义颜色
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)# 定义粒子类
class Particle:def __init__(self, x, y, color):self.x = xself.y = yself.color = colorself.radius = 3self.angle = randint(0, 360)self.speed = randint(1, 5)self.gravity = 0.1self.life = randint(20, 25)def update(self):if self.life > 0:radian = math.radians(self.angle)self.x += self.speed * math.cos(radian)self.y -= self.speed * math.sin(radian)self.speed -= self.gravityself.life -= 1def draw(self):pygame.draw.circle(win, self.color, (int(self.x), int(self.y)), self.radius)# 定义烟花类
class Firework:def __init__(self):self.x = randint(100, DISPLAY_WIDTH - 100)self.y = DISPLAY_HEIGHTself.color = (randint(0, 255), randint(0, 255), randint(0, 255))self.particles = []self.exploded = Falsedef explode(self):for _ in range(100):particle = Particle(self.x, self.y, self.color)self.particles.append(particle)def update(self):if not self.exploded:self.y -= 3if self.y <= randint(200, 400):self.explode()self.exploded = Trueelse:for particle in self.particles:particle.update()def draw(self):pygame.draw.circle(win, self.color, (int(self.x), int(self.y)), 5)# 创建烟花列表
fireworks = []# 游戏主循环
running = True
clock = pygame.time.Clock()while running:clock.tick(60)for event in pygame.event.get():if event.type == pygame.QUIT:running = Falsewin.fill(BLACK)# 添加新的烟花if len(fireworks) < 10 and randint(0, 100) < 2:fireworks.append(Firework())# 更新和绘制烟花for firework in fireworks:firework.update()firework.draw()for particle in firework.particles:particle.draw()# 移除完成的烟花及消失的粒子fireworks = [firework for firework in fireworks if not firework.exploded or len(firework.particles) > 0]for firework in fireworks:firework.particles = [particle for particle in firework.particles if particle.life > 0]pygame.display.update()pygame.quit()

        通过上述步骤,我们已经成功创建了一个令人惊叹的烟花盛典。在这个过程中,我们学习了如何使用 Pygame 库和 Python 编程,创建粒子类和烟花类,并在主循环中更新和绘制烟花效果。

    给大家推荐一个网站

    IT今日热榜 一站式资讯平台


        里面包含了上百个IT网站,欢迎大家访问:IT今日热榜 一站式资讯平台

   iToday,打开信息的新时代。作为一家创新的IT数字媒体平台,iToday致力于为用户提供最新、最全面的IT资讯和内容。里面包含了技术资讯、IT社区、面试求职、前沿科技等诸多内容。我们的团队由一群热爱创作的开发者和分享的专业编程知识爱好者组成,他们精选并整理出真实可信的信息,确保您获得独特、有价值的阅读体验。随时随地,尽在iToday,与世界保持连接,开启您的信息新旅程!

IT今日热榜 一站式资讯平台IT今日热榜汇聚各类IT热榜:虎嗅、知乎、36氪、京东图书销售、晚点、全天候科技、极客公园、GitHub、掘金、CSDN、哔哩哔哩、51CTO、博客园、GitChat、开发者头条、思否、LeetCode、人人都是产品经理、牛客网、看准、拉勾、Boss直聘http://itoday.top/#/

http://www.yayakq.cn/news/549409/

相关文章:

  • 移动网站建设方面wordpress编辑页面上方有白条
  • 低价网站建设公司公司做网站流程
  • 龙岗网站建设流程免费舆情信息网站
  • cms管理手机网站模板下载八亿免费wap自助建站
  • 选择网站建设公司网站开发确认书
  • 网站做地区定位跳转企业展馆设计企业
  • 襄樊网站推广wordpress条件查询插件
  • 个人设计师网站 青春珠海网站建设工程
  • 西安免费建网站制作自己的网站怎么做搜索
  • 营销网站建设公司有哪些临沂网站建设
  • 河北建设厅八大员报名网站婚礼策划网站模板
  • 做网站的编程语言做家乡特产的网站
  • 教怎么做ppt的网站江西省城乡建设陪训网官方网站
  • 温州谷歌seoseo数据是什么
  • 面试建设单位在哪个网站网页设计网站建设过程报告
  • 网站建设昆明包装设计大连网站设计案例
  • 有哪些做软件的网站绿色风格网站
  • 五种类型网站免费logo设计软件手机版
  • 天津建设网站安全员考试查询一个页面的网站
  • 海口 网站 制作网页传奇3
  • 网站建设制作首页流程canvas 特效网站
  • 网站维护难做wordpress管理历史版本
  • 打广告网站关于网站开发的外文书籍
  • 安康网站建设公司报价天津设计网站
  • 应该符合建设网站wordpress 文章 分类
  • 为什么最近好多网站打不开了手机网站 代码格式
  • php商城网站开发实例视频教程西安个人做网站
  • 企业做网站的目的是什么湖南高端建设网站
  • 网站怎样做银联支付潍坊市住房和城乡建设局网站下载
  • 漂亮大气的装潢室内设计网站模板 单页式html5网页模板包厦门编程培训机构