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

asp.net网站思路百度搜索风云榜总榜

asp.net网站思路,百度搜索风云榜总榜,七星彩的网站怎么做的,怎么建立一个简易的网站目录 功能概括 安装依赖 版本1 动态粒子爱心 执行代码 运行效果 版本2:优化粒子点缀 执行代码 运行效果 版本3:增加例子密度 执行代码 运行效果 版本4:改成粉色粒子 执行代码 运行效果 功能概括 使用 pygame 实现了一个动态的 心…

目录

功能概括

安装依赖

版本1 动态粒子爱心

执行代码

 运行效果

版本2:优化粒子点缀

执行代码

运行效果 

 版本3:增加例子密度

执行代码

运行效果

版本4:改成粉色粒子

 执行代码

运行效果


功能概括

使用 pygame 实现了一个动态的 心形粒子特效动画。主要功能包括:

  • 在屏幕中心通过心形参数方程生成粒子轨迹;

  • 每个粒子具有独立的大小、速度、角度、寿命和随机扰动;

  • 粒子逐渐缩小并淡出,营造浪漫柔和的视觉效果;

  • 采用 asyncio 实现异步主循环,保持帧率稳定在 60 FPS;

  • 自动循环更新粒子,实现持续动态效果;

  • 可兼容 Web 环境(通过对 platform.system() 判断 Emscripten 进行适配)。

【运行效果】

动态粒子爱心-CSDN直播


安装依赖

pip install pygame

版本1 动态粒子爱心

执行代码

import asyncio
import platform
import pygame
import random
import math# 初始化Pygame
pygame.init()# 屏幕设置
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Enhanced Heart Particle Effect")# 颜色定义
WHITE = (255, 255, 255)
RED = (255, 0, 0)
PINK = (255, 192, 203)
DARK_PINK = (255, 105, 180)# 粒子类
class Particle:def __init__(self, x, y):self.x = xself.y = yself.size = random.uniform(3, 6)self.color = random.choice([PINK, DARK_PINK, RED])self.speed = random.uniform(0.3, 1.5)self.angle = random.uniform(0, 2 * math.pi)self.lifetime = random.randint(80, 160)self.age = 0self.offset_x = random.uniform(-5, 5)self.offset_y = random.uniform(-5, 5)def update(self):# 心形路径的参数方程t = self.anglescale = 18  # 放大心形base_x = scale * 16 * (math.sin(t) ** 3)base_y = -(scale * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t)))# 平滑移动到目标位置self.x += (WIDTH / 2 + base_x + self.offset_x - self.x) * 0.1self.y += (HEIGHT / 2 + base_y + self.offset_y - self.y) * 0.1self.age += 1self.size = max(1, self.size * 0.985)  # 更慢的缩小速度self.angle += self.speed * 0.02  # 缓慢旋转def draw(self, surface):if self.age < self.lifetime:alpha = max(0, 255 * (1 - self.age / self.lifetime))color = (*self.color[:3], int(alpha))pygame.draw.circle(surface, color, (int(self.x), int(self.y)), int(self.size))# 粒子列表
particles = []def setup():global particlesparticles = [Particle(WIDTH / 2, HEIGHT / 2) for _ in range(400)]  # 增加粒子数量def update_loop():global particlesscreen.fill((10, 10, 20))  # 深色背景增强对比# 更新和绘制粒子for particle in particles[:]:particle.update()particle.draw(screen)if particle.age >= particle.lifetime:particles.remove(particle)particles.append(Particle(WIDTH / 2, HEIGHT / 2))pygame.display.flip()async def main():setup()clock = pygame.time.Clock()while True:for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()returnupdate_loop()clock.tick(60)await asyncio.sleep(1.0 / 60)if platform.system() == "Emscripten":asyncio.ensure_future(main())
else:if __name__ == "__main__":asyncio.run(main())

 运行效果

动态效果:动态粒子爱心-CSDN直播


版本2:优化粒子点缀

执行代码

import asyncio
import platform
import pygame
import random
import math# 初始化Pygame
pygame.init()# 屏幕设置
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Enhanced Heart Particle Effect")# 颜色定义
WHITE = (255, 255, 255)
RED = (255, 0, 0)
PINK = (255, 192, 203)
DARK_PINK = (255, 105, 180)
SOFT_PINK = (255, 182, 193)# 粒子类
class Particle:def __init__(self, x, y, is_decorative=False):self.x = xself.y = yself.is_decorative = is_decorativeself.size = random.uniform(2, 5) if is_decorative else random.uniform(3, 7)self.color = random.choice([PINK, DARK_PINK, RED, SOFT_PINK])self.speed = random.uniform(0.2, 1.2) if not is_decorative else random.uniform(0.1, 0.5)self.angle = random.uniform(0, 2 * math.pi)self.lifetime = random.randint(100, 200) if not is_decorative else random.randint(50, 150)self.age = 0self.offset_x = random.uniform(-8, 8) if not is_decorative else random.uniform(-50, 50)self.offset_y = random.uniform(-8, 8) if not is_decorative else random.uniform(-50, 50)def update(self):if not self.is_decorative:# 心形路径的参数方程t = self.anglescale = 20  # 放大心形base_x = scale * 16 * (math.sin(t) ** 3)base_y = -(scale * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t)))# 平滑移动到目标位置self.x += (WIDTH / 2 + base_x + self.offset_x - self.x) * 0.15self.y += (HEIGHT / 2 + base_y + self.offset_y - self.y) * 0.15else:# 点缀粒子随机漂浮self.x += random.uniform(-1, 1)self.y += random.uniform(-1, 1)self.x = max(0, min(WIDTH, self.x))self.y = max(0, min(HEIGHT, self.y))self.age += 1self.size = max(1, self.size * 0.98)  # 更慢的缩小速度self.angle += self.speed * 0.015  # 更慢的旋转def draw(self, surface):if self.age < self.lifetime:alpha = max(0, 255 * (1 - self.age / self.lifetime))color = (*self.color[:3], int(alpha))pygame.draw.circle(surface, color, (int(self.x), int(self.y)), int(self.size))# 粒子列表
particles = []def setup():global particles# 主心形粒子particles = [Particle(WIDTH / 2, HEIGHT / 2) for _ in range(600)]  # 增加粒子数量# 点缀粒子particles.extend([Particle(random.randint(0, WIDTH), random.randint(0, HEIGHT), is_decorative=True) for _ in range(200)])def update_loop():global particlesscreen.fill((10, 10, 20))  # 深色背景增强对比# 更新和绘制粒子for particle in particles[:]:particle.update()particle.draw(screen)if particle.age >= particle.lifetime:particles.remove(particle)if particle.is_decorative:particles.append(Particle(random.randint(0, WIDTH), random.randint(0, HEIGHT), is_decorative=True))else:particles.append(Particle(WIDTH / 2, HEIGHT / 2))pygame.display.flip()async def main():setup()clock = pygame.time.Clock()while True:for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()returnupdate_loop()clock.tick(60)await asyncio.sleep(1.0 / 60)if platform.system() == "Emscripten":asyncio.ensure_future(main())
else:if __name__ == "__main__":asyncio.run(main())

运行效果 


 版本3:增加例子密度

执行代码

import asyncio
import platform
import pygame
import random
import math# 初始化Pygame
pygame.init()# 屏幕设置
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Dense 3D Heart Particle Effect")# 颜色定义
WHITE = (255, 255, 255)
RED = (255, 0, 0)
PINK = (255, 192, 203)
DARK_PINK = (255, 105, 180)
SOFT_PINK = (255, 182, 193)# 粒子类
class Particle:def __init__(self, x, y, is_decorative=False):self.x = xself.y = yself.z = random.uniform(-50, 50) if not is_decorative else random.uniform(-100, 100)self.is_decorative = is_decorativeself.size = random.uniform(2, 5) if is_decorative else random.uniform(2, 7)  # 调整主粒子大小self.color = random.choice([PINK, DARK_PINK, RED, SOFT_PINK])self.speed = random.uniform(0.2, 1.2) if not is_decorative else random.uniform(0.1, 0.5)self.angle = random.uniform(0, 2 * math.pi)self.lifetime = random.randint(100, 200) if not is_decorative else random.randint(50, 150)self.age = 0self.offset_x = random.uniform(-8, 8) if not is_decorative else random.uniform(-50, 50)self.offset_y = random.uniform(-8, 8) if not is_decorative else random.uniform(-50, 50)self.offset_z = random.uniform(-10, 10) if not is_decorative else random.uniform(-20, 20)def update(self):if not self.is_decorative:# 心形路径的参数方程t = self.anglescale = 20base_x = scale * 16 * (math.sin(t) ** 3)base_y = scale * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t))# 透视投影fov = 200scale_factor = fov / (fov + self.z) if (fov + self.z) != 0 else 1proj_x = (base_x + self.offset_x) * scale_factorproj_y = (base_y + self.offset_y) * scale_factor# 平滑移动self.x += (WIDTH / 2 + proj_x - self.x) * 0.15self.y += (HEIGHT / 2 - proj_y - self.y) * 0.15self.z += (self.offset_z - self.z) * 0.1else:# 点缀粒子随机漂浮self.x += random.uniform(-1, 1)self.y += random.uniform(-1, 1)self.z += random.uniform(-0.5, 0.5)self.x = max(0, min(WIDTH, self.x))self.y = max(0, min(HEIGHT, self.y))self.z = max(-100, min(100, self.z))self.age += 1self.size = max(1, self.size * 0.98)self.angle += self.speed * 0.015def draw(self, surface):if self.age < self.lifetime:# 计算透视缩放fov = 200scale_factor = fov / (fov + self.z) if (fov + self.z) != 0 else 1adjusted_size = max(1, self.size * scale_factor)alpha = max(0, int(255 * (1 - self.age / self.lifetime) * scale_factor))# 调整亮度,确保整数并在[0, 255]范围内brightness = max(0.5, scale_factor)color = (min(255, max(0, int(self.color[0] * brightness))),min(255, max(0, int(self.color[1] * brightness))),min(255, max(0, int(self.color[2] * brightness))))# 使用透明表面绘制temp_surface = pygame.Surface((int(adjusted_size * 2), int(adjusted_size * 2)), pygame.SRCALPHA)pygame.draw.circle(temp_surface, color, (int(adjusted_size), int(adjusted_size)), int(adjusted_size))temp_surface.set_alpha(alpha)surface.blit(temp_surface, (int(self.x - adjusted_size), int(self.y - adjusted_size)))# 粒子列表
particles = []def setup():global particlesparticles = [Particle(WIDTH / 2, HEIGHT / 2) for _ in range(1000)]  # 增加到1000个主粒子particles.extend([Particle(random.randint(0, WIDTH), random.randint(0, HEIGHT), is_decorative=True) for _ in range(200)])def update_loop():global particlesscreen.fill((10, 10, 20))# 按z轴排序particles.sort(key=lambda p: p.z, reverse=True)# 更新和绘制for particle in particles[:]:particle.update()particle.draw(screen)if particle.age >= particle.lifetime:particles.remove(particle)if particle.is_decorative:particles.append(Particle(random.randint(0, WIDTH), random.randint(0, HEIGHT), is_decorative=True))else:particles.append(Particle(WIDTH / 2, HEIGHT / 2))pygame.display.flip()async def main():setup()clock = pygame.time.Clock()while True:for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()returnupdate_loop()clock.tick(60)await asyncio.sleep(1.0 / 60)if platform.system() == "Emscripten":asyncio.ensure_future(main())
else:if __name__ == "__main__":asyncio.run(main())

运行效果


版本4:改成粉色粒子

 执行代码

import asyncio
import platform
import pygame
import random
import math
import colorsys# 初始化Pygame
pygame.init()# 屏幕设置
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Bright Romantic 3D Heart Particle Effect")# 颜色定义
WHITE = (255, 255, 255)
SOFT_PINK = (255, 182, 193)# 创意参数
PULSE_INTERVAL = 5000  # 脉冲间隔(毫秒)
EXPLOSION_INTERVAL = 5000  # 爆炸间隔(毫秒)
last_pulse = 0
last_explosion = 0
explosion_particles = []# 粒子类
class Particle:def __init__(self, x, y, is_decorative=False, is_explosion=False):self.x = xself.y = yself.z = random.uniform(-50, 50) if not is_decorative else random.uniform(-100, 100)self.is_decorative = is_decorativeself.is_explosion = is_explosionself.size = random.uniform(2, 5) if is_decorative else random.uniform(2, 7) if not is_explosion else random.uniform(1, 3)self.color_hue = random.uniform(0.9, 0.1)  # 限制到粉红-红色-紫色区间self.speed = random.uniform(0.2, 1.2) if not (is_decorative or is_explosion) else random.uniform(0.1, 0.5)self.angle = random.uniform(0, 2 * math.pi)self.lifetime = random.randint(100, 200) if not is_decorative else random.randint(50, 150) if not is_explosion else random.randint(30, 60)self.age = 0self.offset_x = random.uniform(-8, 8) if not (is_decorative or is_explosion) else random.uniform(-50, 50) if is_decorative else random.uniform(-10, 10)self.offset_y = random.uniform(-8, 8) if not (is_decorative or is_explosion) else random.uniform(-50, 50) if is_decorative else random.uniform(-10, 10)self.offset_z = random.uniform(-10, 10) if not (is_decorative or is_explosion) else random.uniform(-20, 20) if is_decorative else random.uniform(-5, 5)def update(self):if self.is_explosion:# 爆炸粒子向外扩散self.x += self.offset_x * 0.1self.y += self.offset_y * 0.1self.z += self.offset_z * 0.05self.size *= 0.95  # 逐渐缩小elif not self.is_decorative:# 心形路径t = self.anglescale = 20base_x = scale * 16 * (math.sin(t) ** 3)base_y = scale * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t))fov = 200scale_factor = fov / (fov + self.z) if (fov + self.z) != 0 else 1proj_x = (base_x + self.offset_x) * scale_factorproj_y = (base_y + self.offset_y) * scale_factorself.x += (WIDTH / 2 + proj_x - self.x) * 0.15self.y += (HEIGHT / 2 - proj_y - self.y) * 0.15self.z += (self.offset_z - self.z) * 0.1self.angle += self.speed * 0.015else:# 点缀粒子self.x += random.uniform(-1, 1)self.y += random.uniform(-1, 1)self.z += random.uniform(-0.5, 0.5)self.x = max(0, min(WIDTH, self.x))self.y = max(0, min(HEIGHT, self.y))self.z = max(-100, min(100, self.z))self.age += 1self.size = max(1, self.size * 0.98)def draw(self, surface):if self.age < self.lifetime:fov = 200scale_factor = fov / (fov + self.z) if (fov + self.z) != 0 else 1adjusted_size = max(1, self.size * scale_factor)alpha = max(0, int(255 * (1 - self.age / self.lifetime) * scale_factor))# 彩虹色渐变,限定爱心色调,增加亮度hue = (self.color_hue + pygame.time.get_ticks() / 10000) % 0.2 + 0.9  # 循环在0.9-1.1范围内color = colorsys.hsv_to_rgb(hue % 1, 0.4, 0.95)  # 亮度提升到0.95color = (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))temp_surface = pygame.Surface((int(adjusted_size * 2), int(adjusted_size * 2)), pygame.SRCALPHA)pygame.draw.circle(temp_surface, color, (int(adjusted_size), int(adjusted_size)), int(adjusted_size))temp_surface.set_alpha(alpha)surface.blit(temp_surface, (int(self.x - adjusted_size), int(self.y - adjusted_size)))# 粒子列表
particles = []def setup():global particlesparticles = [Particle(WIDTH / 2, HEIGHT / 2) for _ in range(1000)]particles.extend([Particle(random.randint(0, WIDTH), random.randint(0, HEIGHT), is_decorative=True) for _ in range(200)])def update_loop():global particles, last_pulse, last_explosion, explosion_particlescurrent_time = pygame.time.get_ticks()# 绘制动态光晕if current_time - last_pulse > PULSE_INTERVAL:last_pulse = current_timepulse_radius = 50 * (1 + 0.5 * math.sin(current_time / 500))  # 心跳脉冲for r in range(int(pulse_radius), 0, -1):alpha = int(150 * (r / pulse_radius))  # 增加光晕亮度color = (255, 182, 193, alpha)  # 柔和粉色pygame.draw.circle(screen, color[:3], (WIDTH // 2, HEIGHT // 2), r, 1)# 触发粒子爆炸if current_time - last_explosion > EXPLOSION_INTERVAL:last_explosion = current_timefor _ in range(100):explosion_particles.append(Particle(WIDTH // 2, HEIGHT // 2, is_explosion=True))screen.fill((10, 10, 20))# 更新和绘制爆炸粒子for p in explosion_particles[:]:p.update()p.draw(screen)if p.age >= p.lifetime:explosion_particles.remove(p)# 按z轴排序all_particles = particles + explosion_particlesall_particles.sort(key=lambda p: p.z, reverse=True)# 更新和绘制for particle in all_particles[:]:particle.update()particle.draw(screen)if particle.age >= particle.lifetime and particle in particles:particles.remove(particle)if particle.is_decorative:particles.append(Particle(random.randint(0, WIDTH), random.randint(0, HEIGHT), is_decorative=True))else:particles.append(Particle(WIDTH / 2, HEIGHT // 2))pygame.display.flip()async def main():setup()clock = pygame.time.Clock()while True:for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()returnupdate_loop()clock.tick(60)await asyncio.sleep(1.0 / 60)if platform.system() == "Emscripten":asyncio.ensure_future(main())
else:if __name__ == "__main__":asyncio.run(main())

运行效果

http://www.dtcms.com/wzjs/409684.html

相关文章:

  • php制作网站用什么软件软文客
  • 宁波企业做网站哪家好搜索引擎优化心得体会
  • 日本做衣服的网站有哪些南宁seo产品优化服务
  • 做公司网站联系公司免费做网站怎么做网站吗
  • 千图网素材下载网站优化大师网页版
  • 网站建设低价建站seo链接优化建议
  • 新网站建设方案ppt济南seo顾问
  • 真人做爰中国视频网站百度的seo关键词优化怎么弄
  • 湖南企业名录大全巩义关键词优化推广
  • 站点推广策略包括网站排名优化手机
  • 做app找哪个网站朝阳seo排名优化培训
  • 毕业设计做网站做什么好哈尔滨最新疫情通报
  • 营销型网站设计案例上海关键词自动排名
  • 艺术品网站开发中国广告公司前十强
  • wordpress大学 视频教程成都seo网络优化公司
  • 简易个人网页模板seo综合诊断工具
  • 宜宾公司做网站长沙seo排名公司
  • 试客网站 源码家庭优化大师免费下载
  • 云南公司网站开发网络网站
  • 2018做网站开发一个月工资多少网络营销环境的分析主要是
  • 信用门户网站建设semester
  • 百度账号快速注册seo 优化顾问
  • 外贸平台哪个网站最好批发重庆百度推广seo
  • 网站开发定制合同范本网站地址ip域名查询
  • 世界疫情最新消息数据seo是做什么的
  • 旅游区网站开发搜狗收录
  • 工商信息查询官网宁波seo外包推广公司
  • 泉州建设网站公司吗附近哪里有计算机培训班
  • 旅游网站建设公司百度seo如何快速排名
  • 在哪些网站做外贸好中山seo关键词