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

济宁做企业网站如何上传文件到网站

济宁做企业网站,如何上传文件到网站,服务器站点的网站地图怎么做,搜索引擎排名优化是什么意思python和pygame实现烟花特效 新年来临之际,来一个欢庆新年烟花祝贺,需要安装使用第三方库pygame,关于Python中pygame游戏模块的安装使用可见 https://blog.csdn.net/cnds123/article/details/119514520 效果图及源码 先看效果图&#xff1a…

python和pygame实现烟花特效

新年来临之际,来一个欢庆新年烟花祝贺,需要安装使用第三方库pygame,关于Python中pygame游戏模块的安装使用可见 https://blog.csdn.net/cnds123/article/details/119514520

效果图及源码

先看效果图:

源码如下:

import pygame
import random
import math# 初始化pygame
pygame.init()# 设置窗口大小
width, height = 800, 600
screen = pygame.display.set_mode((width, height))# 定义颜色
black = (0, 0, 0)
red = (255, 0, 0)# 定义烟花粒子
class Particle:def __init__(self, x, y, color):self.x = xself.y = yself.color = colorself.radius = random.randint(2, 4)self.angle = random.uniform(0, 2 * math.pi)self.speed = random.uniform(1, 3)self.gravity = 0.1def move(self):self.x += math.cos(self.angle) * self.speedself.y += math.sin(self.angle) * self.speed + self.gravityself.radius -= 0.1  # 粒子逐渐变小def draw(self):pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), int(self.radius))# 定义烟花
class Firework:def __init__(self, x, y):self.x = xself.y = yself.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))self.particles = []self.exploded = Falseself.explode_height = random.randint(100, 400)  # 设置爆炸高度self.speed = random.randint(5, 10)  # 设置上升速度self.angle = math.pi / 2  # 设置上升角度为垂直向上def launch(self):if not self.exploded:self.y -= self.speed * math.sin(self.angle)if self.y <= self.explode_height:  # 到达设定高度后爆炸self.explode()self.exploded = Truedef explode(self):for _ in range(100):  # 爆炸产生的粒子数量self.particles.append(Particle(self.x, self.y, self.color))def draw(self):if not self.exploded:pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), 5)else:for particle in self.particles:particle.move()particle.draw()#显示文字
#font = pygame.font.Font(None, 36)  # 设置字体和大小                
font = pygame.font.Font("C:\\Windows\\Fonts\\simsun.ttc", 36)        
text = font.render("龙年快乐", True, red)  # 渲染文本
text_rect = text.get_rect(center=(width // 2, height // 2))  # 获取文本的矩形区域# 主循环
fireworks = []
clock = pygame.time.Clock()
running = True
while running:clock.tick(30)  # 控制帧率for event in pygame.event.get():if event.type == pygame.QUIT:running = Falsescreen.fill(black)# 绘制文本screen.blit(text, text_rect)# 发射烟花if random.randint(1, 20) == 1:  # 控制烟花发射频率fireworks.append(Firework(random.randint(0, width), height))# 更新烟花并绘制for firework in fireworks[:]:firework.launch()firework.draw()if firework.exploded and all(p.radius <= 0 for p in firework.particles):fireworks.remove(firework)pygame.display.flip()pygame.quit()

pygame在屏幕上显示字体的方法说明

使用pygame.font.Font函数来设置字体和大小,然后使用font.render函数将文本渲染为图像。最后,使用screen.blit函数将渲染好的文本图像绘制到屏幕上。

pygame.font.Font(None, 字体大小)使用系统默认字体,可能不支持汉字。None代表系统默认字体,如pygame.font.Font(None, 36),可能不支持汉字。怎么办?使用pygame.font. Font(“含路径的字体名”,字体大小),指定支持汉字的字体,如:pygame.font.Font("C:\\Windows\\Fonts\\simsun.ttc", 36),simsun.ttc是宋体,字体的路径和名称。在windows中如何确定字体的路径和名称呢?参见下图

改进:添加背景音乐,增添欢乐的气氛

在“# 主循环”部分前,添加如下代码

# 载入背景音乐
pygame.mixer.music.load("踩着开心的节奏 - 橙光音乐.mp3")
pygame.mixer.music.set_volume(0.5)  # 设置音量
pygame.mixer.music.play(-1)  #  播放背景音乐,-1表示循环播放

其中,pygame.mixer.music.load函数加载背景音乐文件(例如名为"踩着开心的节奏 - 橙光音乐.mp3"文件,并将其放在与代码文件相同的目录下),然后使用pygame.mixer.music.set_volume函数设置音量大小(范围为0.0-1.0)。最后,使用pygame.mixer.music.play函数播放背景音乐,参数-1表示循环播放。

请你使用自己背景音乐文件替换"踩着开心的节奏 - 橙光音乐.mp3",只要保证正确命名文件名和路径即可。

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

相关文章:

  • 做殡葬名片的网站wordpress实现多用户
  • 手机网站免费手机app设计网站
  • 速贝网站友情链接怎么做建设银行可以查房贷的网站
  • 自己买一台服务器做自己的网站泰州网站建设价位
  • 企业网站多少钱一套完整的vi设计手册
  • 网站子域名怎么设置福州网站建设索q479185700
  • 江苏省高校品牌专业建设网站三亚网站外包
  • 网站做联盟广告能赚钱吗网络营销型网站建设的内容
  • wordpress网站价格wordpress图书页面
  • 安顺市网站建设邯郸建移动网站费用
  • asp网站添加背景音乐2022年进口博览会上海
  • joomla网站建设wordpress新站不收录
  • 山西省住房建设厅网站下载专做国外商品的网站
  • 企业网站构建方案管理手机网站首页
  • 网站地址查询域名做网站前产品经理要了解什么
  • 用asp.net做的购物网站北京网站排名优化公司
  • 北京道路建设在什么网站查询北京南站是高铁站吗
  • 如何创建一个网站用来存放东西sem是什么显微镜
  • 在哪些网站上做推广好内丘附近网站建设价格
  • 极乐宝盒网站建设云空间布置网站
  • 长沙网站建设流程企业建立网站的原因
  • 关掉自己做的网站莱州网站制作
  • 外贸型网站该如何推广营销型企业网站测评表
  • 网站主机购买网络规划与设计实验报告
  • 网页设计简单的网站石家庄网络公司哪家好
  • 沧州市东光建设局 网站wordpress用户增加插件
  • 网站开发完没人运营英文商城网站模板
  • 北京网站建设方案托管永定路网站建设
  • 请网站制作公司费用最专业的外贸网站建设公司
  • 贸易网站开发腾讯学生机wordpress