Skip to content

Commit

Permalink
fireworks test
Browse files Browse the repository at this point in the history
  • Loading branch information
ToonTalk committed Oct 18, 2024
1 parent fe37091 commit 75e72e1
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions apps/beautiful_fireworks_updated by 4o.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Beautiful Fireworks</title>
<style>
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #000;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="fireworksCanvas"></canvas>

<script>
const canvas = document.getElementById('fireworksCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

let particles = [];

function random(min, max) {
return Math.random() * (max - min) + min;
}

class Particle {
constructor(x, y, radius, color, velocity) {
this.x = x;
this.y = y;
this.radius = radius;
this.color = color;
this.velocity = velocity;
this.alpha = 1;
}

draw() {
ctx.save();
ctx.globalAlpha = this.alpha;
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
ctx.fillStyle = this.color;
ctx.fill();
ctx.restore();
}

update() {
this.draw();
this.velocity.x *= 0.99;
this.velocity.y *= 0.99;
this.x += this.velocity.x;
this.y += this.velocity.y;
this.alpha -= 0.01;
}
}

function createFirework(x, y) {
const particlesCount = 50;
const colors = ['#FF1461', '#18FF92', '#5A87FF', '#FBF38C', '#FF8C00', '#00FF00', '#00FFFF', '#FFD700', '#FF69B4', '#8A2BE2', '#DC143C', '#00BFFF'];
for (let i = 0; i < particlesCount; i++) {
const angle = Math.random() * Math.PI * 2;
const speed = Math.random() * 5 + 2;
particles.push(new Particle(
x,
y,
3,
colors[Math.floor(Math.random() * colors.length)],
{
x: Math.cos(angle) * speed,
y: Math.sin(angle) * speed
}
));
}
}

function animate() {
requestAnimationFrame(animate);
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
particles = particles.filter(p => p.alpha > 0);
particles.forEach(p => p.update());
}

window.addEventListener('click', (event) => {
createFirework(event.clientX, event.clientY);
});

animate();
</script>
</body>
</html>

0 comments on commit 75e72e1

Please sign in to comment.