html/jsp +css+js烟花代码,可变换字体,随鼠标移动-有源码

效果图:
在这里插入图片描述
在这里插入图片描述
上代码:

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>surprised</title>
<link rel="stylesheet" href="css/style.css">
<style>
body {
  margin: 0;
  background: black;
}
canvas {
  position: absolute;
}
</style>
</head>
<body>
<canvas></canvas>
<canvas></canvas>
<canvas></canvas>
<script type="text/javascript">

// CLASSES
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));
    }
  }}


// 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 = '鸡你太美';   
     
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>

喜欢就留下关注点赞吧,收藏以防丢失。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: HTML是一种标记语言,用于创建网页的内容和结构。它提供了一系列元素,用于定义文本、图像、链接等。CSS是层叠样式表,用于定义网页的样式,包括字体、颜色、布局等。JavaScript是一种脚本语言,用于在网页中添加交互性和动态特效。 JSPJava服务器页面的缩写,它允许在网页中嵌入Java代码JSP通过将Java代码嵌入到HTML中,动态生成网页内容。Javabeans是一种Java组件模型,用于创建可重用的软件组件。它可以在JSP中使用,提供封装的业务逻辑,并通过属性访问器和方法调用来与页面交互。 SQL Server 2008是一种关系数据库管理系统,用于存储和管理结构化数据。它支持使用结构化查询语言(SQL)进行数据查询和操作。 HTMLCSSJavaScript通常用于前端开发,负责创建网页的外观和交互性。JSPJavabeans则在后端开发中使用,负责处理业务逻辑和与数据库的交互。SQL Server 2008作为数据库管理系统,用于存储和管理数据。 综上所述,HTMLCSSJavaScript用于创建网页的外观和交互性,而JSPJavabeans用于处理业务逻辑和与数据库的交互,SQL Server 2008用于存储和管理数据。它们是Web开发中常用的技术和工具。 ### 回答2: HTML(超文本标记语言)是一种用于创建和组织网页内容的标记语言。通过使用HTML元素,开发者可以定义文本、图像、链接和其他类型的内容,并对它们进行布局和格式化。 CSS(层叠样式表)是一种用于描述网页显示样式的语言。通过使用CSS,开发者可以选择性地控制网页元素的外观和布局,如字体、颜色、大小、边距和背景等。 JavaScript 是一种用于开发交互式和动态网页的编程语言。通过使用JavaScript,开发者可以对网页中的元素进行操作,如改变内容、添加事件监听器、执行动画效果等。 JSPJava服务器页面)是一种用于创建动态网页的基于Java的技术。它允许开发者在HTML页面中嵌入Java代码,以便根据特定的逻辑和数据生成动态内容。 JavaBeans 是一种用于创建可重用Java组件的规范。它使用简单Java类来封装数据和行为,并可以在不同的应用程序中重复使用。 SQL Server 2008 是一种关系型数据库管理系统(RDBMS),用于存储和管理大量结构化数据。它使用结构化查询语言(SQL)来操作和查询数据库中的数据。 通过使用HTMLCSSJavaScript,开发者可以构建具有丰富功能和良好用户体验的网页。JSPJavaBeans则为开发者提供了更高级的交互性和生成动态内容的能力。而SQL Server 2008 则提供了数据的持久性和可靠性,以便于应用程序的数据管理和访问。这些技术的结合使得开发者能够创造出功能丰富、动态交互的网页应用程序。 ### 回答3: HTML(超文本标记语言),CSS(层叠样式表),JavaScript是前端开发中的三个基本技术。HTML用于构建网页的结构,CSS用于定义网页的样式,JavaScript用于实现网页的交互功能。通过这三种技术的组合,我们可以创建出美观、实用的网页。 JSPJavaServer Pages)是一种使用Java编程语言来开发动态网页的技术。JSP允许我们在HTML网页中插入Java代码,以动态地生成网页内容。同时,我们可以使用Java中的类库和框架来处理数据库、进行业务逻辑处理等功能。 JavaBeans是Java平台上可重用组件的标准规范。JavaBeans是一种特殊的Java类,它遵循特定的命名规则、属性和方法规范。开发人员可以将JavaBeans作为独立的组件,用于处理应用程序中的特定功能。JavaBeans可以与其他Java技术如JSP、Servlet、以及数据库进行配合,实现更为复杂的功能。 SQL Server 2008是微软公司开发的一种关系型数据库管理系统。它使用SQL(结构化查询语言)来管理和处理数据。SQL Server 2008具有高性能、可靠性强以及安全性高等特点。它可以与JSPJavaBeans等技术配合使用,实现数据的存储、检索和处理等操作。 综上所述,HTMLCSSJavaScript用于前端开发,JSPJavaBeans用于后端开发,SQL Server 2008用于数据存储和管理。这些技术和工具的组合可以用来开发全面、功能完善的网站和应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值