HTML2023新年源代码(炫酷动态烟花)

2023-11-12

马上就要迎接新年了,新的一年祝大家前途似锦,兔年吉祥。

1.代码效果展示

烟花会一直绽放,字体会逐渐完整明亮,当然也可以根据自己的需要,更改字体内容用在不同的场景,实现一码多用

2.完整代码(复制即可使用)如下:

<!DOCTYPE html>
<html lang="en">
<script>
  var _hmt = _hmt || [];
  (function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?c923daf3182a4b0ce01878475080aadc";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>
 
<head>
  <meta charset="UTF-8">
  <title>2023,新年快乐!</title>
</head>
<style>
  body {
    margin: 0;
    overflow: hidden;
    background: black;
  }
 
  canvas {
    position: absolute;
  }
</style>
 
<body>
 
  <canvas></canvas>
  <canvas></canvas>
  <canvas></canvas>
 
  <script>
 
    function GetRequest() {
      var url = decodeURI(location.search); //获取url中"?"符后的字串
      var theRequest = new Object();
      if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
          theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
      }
      return theRequest;
    }
    class Shard {
      constructor(x, y, hue) {
        this.x = x;
        this.y = y;
        this.hue = hue;
        this.lightness = 50;
        this.size = 15 + Math.random() * 10;
        const angle = Math.random() * 2 * Math.PI;
        const blastSpeed = 1 + Math.random() * 6;
        this.xSpeed = Math.cos(angle) * blastSpeed;
        this.ySpeed = Math.sin(angle) * blastSpeed;
        this.target = getTarget();
        this.ttl = 100;
        this.timer = 0;
      }
      draw() {
        ctx2.fillStyle = `hsl(${this.hue}, 100%, ${this.lightness}%)`;
        ctx2.beginPath();
        ctx2.arc(this.x, this.y, this.size, 0, 2 * Math.PI);
        ctx2.closePath();
        ctx2.fill();
      }
      update() {
        if (this.target) {
          const dx = this.target.x - this.x;
          const dy = this.target.y - this.y;
          const dist = Math.sqrt(dx * dx + dy * dy);
          const a = Math.atan2(dy, dx);
          const tx = Math.cos(a) * 5;
          const ty = Math.sin(a) * 5;
          this.size = lerp(this.size, 1.5, 0.05);
 
          if (dist < 5) {
            this.lightness = lerp(this.lightness, 100, 0.01);
            this.xSpeed = this.ySpeed = 0;
            this.x = lerp(this.x, this.target.x + fidelity / 2, 0.05);
            this.y = lerp(this.y, this.target.y + fidelity / 2, 0.05);
            this.timer += 1;
          } else
            if (dist < 10) {
              this.lightness = lerp(this.lightness, 100, 0.01);
              this.xSpeed = lerp(this.xSpeed, tx, 0.1);
              this.ySpeed = lerp(this.ySpeed, ty, 0.1);
              this.timer += 1;
            } else {
              this.xSpeed = lerp(this.xSpeed, tx, 0.02);
              this.ySpeed = lerp(this.ySpeed, ty, 0.02);
            }
        } else {
          this.ySpeed += 0.05;
          //this.xSpeed = lerp(this.xSpeed, 0, 0.1);
          this.size = lerp(this.size, 1, 0.05);
 
          if (this.y > c2.height) {
            shards.forEach((shard, idx) => {
              if (shard === this) {
                shards.splice(idx, 1);
              }
            });
          }
        }
        this.x = this.x + this.xSpeed;
        this.y = this.y + this.ySpeed;
      }
    }
 
    class Rocket {
      constructor() {
        const quarterW = c2.width / 4;
        this.x = quarterW + Math.random() * (c2.width - quarterW);
        this.y = c2.height - 15;
        this.angle = Math.random() * Math.PI / 4 - Math.PI / 6;
        this.blastSpeed = 6 + Math.random() * 7;
        this.shardCount = 15 + Math.floor(Math.random() * 15);
        this.xSpeed = Math.sin(this.angle) * this.blastSpeed;
        this.ySpeed = -Math.cos(this.angle) * this.blastSpeed;
        this.hue = Math.floor(Math.random() * 360);
        this.trail = [];
      }
      draw() {
        ctx2.save();
        ctx2.translate(this.x, this.y);
        ctx2.rotate(Math.atan2(this.ySpeed, this.xSpeed) + Math.PI / 2);
        ctx2.fillStyle = `hsl(${this.hue}, 100%, 50%)`;
        ctx2.fillRect(0, 0, 5, 15);
        ctx2.restore();
      }
      update() {
        this.x = this.x + this.xSpeed;
        this.y = this.y + this.ySpeed;
        this.ySpeed += 0.1;
      }
 
      explode() {
        for (let i = 0; i < 70; i++) {
          shards.push(new Shard(this.x, this.y, this.hue));
        }
      }
    }
 
    console.log(GetRequest('val').val)
    // INITIALIZATION
    const [c1, c2, c3] = document.querySelectorAll('canvas');
    const [ctx1, ctx2, ctx3] = [c1, c2, c3].map(c => c.getContext('2d'));
    let fontSize = 200;
    const rockets = [];
    const shards = [];
    const targets = [];
    const fidelity = 3;
    let counter = 0;
    c2.width = c3.width = window.innerWidth;
    c2.height = c3.height = window.innerHeight;
    ctx1.fillStyle = '#000';
    const text = '2023新年快乐!'
    let textWidth = 99999999;
 
    while (textWidth > window.innerWidth) {
      ctx1.font = `900 ${fontSize--}px Arial`;
      textWidth = ctx1.measureText(text).width;
    }
 
    c1.width = textWidth;
    c1.height = fontSize * 1.5;
    ctx1.font = `900 ${fontSize}px Arial`;
    ctx1.fillText(text, 0, fontSize);
    const imgData = ctx1.getImageData(0, 0, c1.width, c1.height);
    for (let i = 0, max = imgData.data.length; i < max; i += 4) {
      const alpha = imgData.data[i + 3];
      const x = Math.floor(i / 4) % imgData.width;
      const y = Math.floor(i / 4 / imgData.width);
 
      if (alpha && x % fidelity === 0 && y % fidelity === 0) {
        targets.push({ x, y });
      }
    }
 
    ctx3.fillStyle = '#FFF';
    ctx3.shadowColor = '#FFF';
    ctx3.shadowBlur = 25;
 
    // ANIMATION LOOP
    (function loop() {
      ctx2.fillStyle = "rgba(0, 0, 0, .1)";
      ctx2.fillRect(0, 0, c2.width, c2.height);
      //ctx2.clearRect(0, 0, c2.width, c2.height);
      counter += 1;
 
      if (counter % 15 === 0) {
        rockets.push(new Rocket());
      }
      rockets.forEach((r, i) => {
        r.draw();
        r.update();
        if (r.ySpeed > 0) {
          r.explode();
          rockets.splice(i, 1);
        }
      });
 
      shards.forEach((s, i) => {
        s.draw();
        s.update();
 
        if (s.timer >= s.ttl || s.lightness >= 99) {
          ctx3.fillRect(s.target.x, s.target.y, fidelity + 1, fidelity + 1);
          shards.splice(i, 1);
        }
      });
 
      requestAnimationFrame(loop);
    })();
 
    // HELPER FUNCTIONS
    const lerp = (a, b, t) => Math.abs(b - a) > 0.1 ? a + t * (b - a) : b;
 
    function getTarget() {
      if (targets.length > 0) {
        const idx = Math.floor(Math.random() * targets.length);
        let { x, y } = targets[idx];
        targets.splice(idx, 1);
 
        x += c2.width / 2 - textWidth / 2;
        y += c2.height / 2 - fontSize / 2;
 
        return { x, y };
      }
    }
  </script>
 
</body>
 
</html>

3.如何使用,会前端的不用多说,小白如何使用?

(1)复制代码

(2)在电脑桌面新建记事本txt(大神一般都用txt)

(3)在记事本内粘贴代码并保存

(4)最后将记事本txt后缀改为html,点击最后的html文件即可

4.下一个365天,希望大家保持开心

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

HTML2023新年源代码(炫酷动态烟花) 的相关文章

随机推荐

  • 关于内存地址和内存空间的理解。

    1 内存地址用4位16进制和8位16进制表示的区别 例如经常可以看到某些书籍上写的内存地址0x0001 在另外一些书籍上写的内存地址又变成了0x00000001 都是表示的编号为1的内存地址 为什么一个是4位16进制表示 另外一个又是用8位
  • MPP架构学习

    原文链接 https blog csdn net qq 42189083 article details 80610092 1 什么是MPP MPP Massively Parallel Processing 即大规模并行处理 在数据库非共
  • PE文件资源解析(九)版本信息资源的解析

    版本信息资源 在这里指的是资源类型为RT VERSION的资源信息 通过ResHacker看到的效果图如下 版本信息资源存储编码格式是UNICODE 解析代码如下 HRSRC hResrc FindResourceEx HMODULE hM
  • 搭建个人深度学习环境(一)—— 单GPU主机配置

    前言 硬件配置 配置表 选择原因 配置总结 系统环境配置及驱动安装 安装ubuntu 16 04 制作启动盘 安装系统 UEFI启动 安装驱动 网卡驱动 显卡驱动 前言 因为实验室服务器不够用 所以准备自己搭建一台搭载高性能GPU的主机作为
  • 用来进行虚拟仿真实验的软件有哪些?这3款简单易懂的软件值得你拥有

    用来进行虚拟仿真实验的软件有哪些 实验教学是高等院校培养高素质合格人才的重要实践性环节 它是学生巩固和加深对理论知识的理解 锻炼在实践中发现问题 分析问题和解决问题的能力 虚拟实验室在培养学生的实践能力 研究能力 创新能力和综合素质等方面有
  • Linux 软连接和硬链接

    Linux 软连接和硬链接的 区别 1 软连接可以 跨文件系统 也即可以跨不同目录分区 而硬连接不可以 2 关于 I节点的问题 硬连接不管有多少个 都指向的是同一个I节点 I节点相同 会把 结点连接数 增加 I节点 也即文件的编号 唯一标示
  • C语言总结规范二:变量

    目录 基本数据类型 复杂数据类型 变量的前缀 变量命名 类型转换 移位 变量 常量 标识符命名 基本数据类型 基本类型使用宏定义替换 复杂数据类型 书写规范 命名区分 后缀增加类型说明 统一格式命名 成员过多则进行拆分成子结构 合理安排元素
  • [leetcode] 球会落何处 模拟

    给出一个矩阵 里面的值为 1 or 1 1的时候是从左上到右下 1的时候是从左下到右上 当一个球从上方x 0 lt x lt m 放入之后 从哪个出口掉落还是无法从出口掉落 能通过的情况为 即某条线为 其左边的线也是 箭头所指为当前斜线 即
  • RC串并联电路工作原理

    一 定义 RC电路全称Resistance Capacitance Circuits 又叫 RC相移电路 RC滤波器 RC网络 是一个包含利用电压源 电流源驱使电阻器 电容器运作的电路 一个最简单的RC电路是由一个电容器和一个电阻器组成的
  • 【华为上机真题】事件推送

    作者 Linux猿 简介 CSDN博客专家 华为云享专家 Linux C C 云计算 物联网 面试 刷题 算法尽管咨询我 关注我 有问题私聊 关注专栏 数据结构和算法成神路 精讲 优质好文持续更新中 欢迎小伙伴们点赞 收藏 留言 目录 一
  • 若依分离版解决单个账号多设备登录问题

    若依分离版解决单个账号多设备登录问题 1 application yml添加相关配置 用于灵活控制单个账号多设备登录的情况 token配置 token 这个是若依框架本身存在的配置 是否允许并多设备登录 true 允许 false 不允许
  • 市面上常见arduino版本比较

    http arduino cc en Main Products 详细链接 如果是入门 那么首选UNO R3 方便又省心 如果不是特殊要求 不建议购买2560 因为贵啊 nano是块很好的控制器 买不买随你咯 非特殊场合使用不建议购买min
  • web服务器集群

    1 源码安装nginx 并提供服务脚本 1 安装 Nginx 所需的 pcre 库 pcre 的全称为 perl compatible regular expressions 中文译为 perl 兼容正则表达式 官方站点为 h ttp ww
  • C语言中数组常用的排序算法

    目录 一 C语言中数组的一些算法 1 1冒泡排序 1 2选择排序 1 3插入排序 1 4快速排序 一 C语言中数组的一些算法 把数据按照从小到大或从大到小 的顺序进行排列 有很多算法 冒泡排序 选择排序 插入排序 快速排序 计数排序 堆排序
  • 计算机系统的5个安全等级,等级保护5个级别介绍及要素与关系分析

    上一篇 什么是信息安全等级保护 中我们了解了等级保护的定义及由来 本篇介绍信息系统等级保护的五个级别及定级原则 信息系统安全保护等级 信息系统的安全保护等级应当根据信息系统在国家安全 经济建设 社会生活中的重要程度 遭到破坏后对国家安全 社
  • 附指南原文下载-《GB/T 39725-2020 信息安全技术 健康医疗数据安全指南》解读(一)

    本文由指南内容的精简总结和笔者个人理解编写而成 指南原文链接在文末 不同数据使用场景的下的安全保护措施因篇幅问题单独编写一章 链接在文末 目录 一 背景 二 数据分类分级 1 数据分类 2 数据分级 3 数据开放形式 三 数据安全管理要求和
  • 创新创意ssm计算机毕业设计题目300例之java农村电商网站3252s

    面对老师五花八门的设计要求 首先自己要明确好自己的题目方向 并且与老师多多沟通 用什么编程语言 使用到什么数据库 确定好了 在开始着手毕业设计 1 选择课题的第一选择就是尽量选择指导老师擅长的课题 其实说白一点 你们的指导老师每年都是那几个
  • 【数学】3、动态规划

    文章目录 一 原理 1 1 如何想到dp 二 案例 2 1 编辑距离 2 1 1 状态转移 2 1 2 状态转移方程和编程实现 2 2 钱币组合 一 原理 接着文本搜索的话题 来聊聊查询推荐 Query Suggestion 的实现过程 以
  • 在请求所选文本中的Java AST期间,发生了内部错误

    添加链接描述 eclipse 在以下过程中发生内部错误 正在从选择 布尔值com ibm icu text UTF16 isSurrogate char 请求Java AST 正在从所选内容请求Java AST在以下过程中发生内部错误 正在
  • HTML2023新年源代码(炫酷动态烟花)

    马上就要迎接新年了 新的一年祝大家前途似锦 兔年吉祥 1 代码效果展示 烟花会一直绽放 字体会逐渐完整明亮 当然也可以根据自己的需要 更改字体内容用在不同的场景 实现一码多用 2 完整代码 复制即可使用 如下
Powered by Hwhale