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

粒子向上持续瀑布动画效果(直接粘贴到记事本改html即可)

代码: 根据个人喜好修改即可

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>宽粒子向上效果</title><style>body {margin: 0;overflow: hidden;background-color: black;}canvas {display: block;}</style>
</head>
<body><canvas id="flameCanvas"></canvas><script>const canvas = document.getElementById('flameCanvas');const ctx = canvas.getContext('2d');canvas.width = window.innerWidth;canvas.height = window.innerHeight;class Particle {constructor(x, y) {this.x = x;this.y = y;this.size = Math.random() * 10 + 5; // 粒子大小this.speedY = Math.random() * -4 - 2; // 向上速度this.speedX = (Math.random() - 0.5) * 2; // 水平随机速度this.color = `rgba(255, ${Math.floor(Math.random() * 100) + 155}, 0, 0.8)`; // 橙色this.friction = 0.98; // 摩擦力}update() {this.x += this.speedX;this.y += this.speedY;this.size *= this.friction; // 粒子逐渐变小if (this.size < 0.5) {this.size = 0; // 粒子消失}}draw() {ctx.fillStyle = this.color;ctx.beginPath();ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);ctx.fill();}}class Flame {constructor(x, width) {this.x = x;this.width = width;this.particles = [];this.particleCount = 40; // 每次生成的粒子数量}update() {// 生成新粒子for (let i = 0; i < this.particleCount; i++) {const particleX = this.x + (Math.random() - 0.5) * this.width; // 生成在宽度范围内this.particles.push(new Particle(particleX, canvas.height));}// 更新粒子位置this.particles.forEach((particle, index) => {particle.update();if (particle.size <= 0) {this.particles.splice(index, 1); // 移除消失的粒子}});}draw() {this.particles.forEach(particle => {particle.draw();});}}const flames = [];const flameWidth = canvas.width * 0.6; // 宽度为屏幕的50%// 创建一束宽粒子flames.push(new Flame(canvas.width / 2, flameWidth));function animate() {ctx.clearRect(0, 0, canvas.width, canvas.height);flames.forEach(flame => {flame.update();flame.draw();});requestAnimationFrame(animate);}animate();</script>
</body>
</html>

http://www.lryc.cn/news/444185.html

相关文章:

  • 卷积神经网络(CNN):深度学习中的视觉奇迹
  • Vue:加载本地视频
  • 论文阅读:A Generalization of Transformer Networks to Graphs
  • 中国计量大学《2022年801+2022年819自动控制原理真题》 (完整版)
  • 创客匠人运营课堂|增强用户的参与度和忠诚度,这一个工具就能实现!
  • k8s 微服务 ingress-nginx 金丝雀发布
  • Elasticsearch不停机切换(上云)方案
  • 归纳一下Invoke,beginInvoke,还有InvokeRequire
  • Prompt最佳实践|指定输出的长度
  • 离散制造 vs 流程制造:锚定精准制造未来,从装配线到化学反应,实时数据集成在制造业案例中的多维应用
  • 教你一招:在微信小程序中为用户上传的图片添加时间水印
  • MySQL --基本查询(上)
  • mysql学习教程,从入门到精通,SQL 删除数据(DELETE 语句)(19)
  • RoguelikeGenerator Pro - Procedural Level Generator
  • 反病毒技术和反病毒软件(网络安全小知识)
  • 位图与布隆过滤器
  • 【题解】—— LeetCode一周小结38
  • EvilScience靶机详解
  • 算法练习题24——leetcode3296移山所需的最小秒数(二分模拟)
  • excel 单元格一直显示年月日
  • 【线程】线程的控制
  • 掌握 Spring:从新手到高手的常见问题汇总
  • 机器学习——Bagging
  • 日志体系结构与框架:历史、实现与如何在 Spring Cloud 中使用日志体系
  • 图文深入理解SQL语句的执行过程
  • ubuntu安装StarQuant
  • 学习篇 | Jupyter 使用(notebook hub)
  • 【裸机装机系列】8.kali(ubuntu)-虚拟内存swap交换分区扩展
  • 异步请求的方法以及原理
  • SpringCloud入门(六)Nacos注册中心(下)