带字的烟花代码html
时间: 2023-10-21 07:06:58 浏览: 58
以下是带字的烟花代码html:
```html
<!DOCTYPE html>
<html>
<head>
<title>带字的烟花</title>
<style type="text/css">
body {
background-color: black;
}
canvas {
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
h1 {
color: white;
font-size: 100px;
text-align: center;
margin-top: 200px;
text-shadow: 2px 2px #FF0000;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<h1>Happy New Year!</h1>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var ctx = canvas.getContext("2d");
var particles = [];
var particleCount = 100;
var particleRadius = 5;
function Particle(x, y, color) {
this.x = x;
this.y = y;
this.color = color;
this.radius = particleRadius;
this.vx = Math.random() * 10 - 5;
this.vy = Math.random() * 10 - 5;
this.gravity = 0.2;
this.alpha = 1;
this.draw = function() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
ctx.fillStyle = this.color;
ctx.globalAlpha = this.alpha; ctx.fill();
ctx.closePath();
}
this.update = function() {
this.x += this.vx;
this.y += this.vy;
this.vy += this.gravity;
this.alpha -= 0.01;
}
}
function createParticles(x, y, color) {
for (var i = 0; i < particleCount; i++) {
var particle = new Particle(x, y, color);
particles.push(particle);
}
}
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < particles.length; i++) {
particles[i].draw();
particles[i].update();
}
}
createParticles(canvas.width / 2, canvas.height / 2, "#FFFFFF");
animate();
</script>
</body>
</html>
```