Changed around line 1
+ class Confetti {
+ constructor() {
+ this.particles = [];
+ this.intensity = 50;
+ this.init();
+ }
+
+ init() {
+ document.getElementById('launchButton').addEventListener('click', () => this.createBurst(window.innerWidth / 2, window.innerHeight / 2));
+ document.addEventListener('click', (e) => this.createBurst(e.clientX, e.clientY));
+ document.addEventListener('scroll', () => this.createBurst(window.innerWidth / 2, window.innerHeight / 2));
+ document.getElementById('intensitySlider').addEventListener('input', (e) => this.intensity = e.target.value);
+
+ window.requestAnimationFrame(this.animate.bind(this));
+ }
+
+ createParticle(x, y) {
+ return {
+ x,
+ y,
+ color: `hsl(${Math.random() * 360}, 80%, 60%)`,
+ size: Math.random() * 10 + 5,
+ speedX: (Math.random() - 0.5) * 15,
+ speedY: Math.random() * -15 - 5,
+ rotation: Math.random() * 360,
+ rotationSpeed: (Math.random() - 0.5) * 10
+ };
+ }
+
+ createBurst(x, y) {
+ const particleCount = Math.floor(this.intensity / 2);
+ for (let i = 0; i < particleCount; i++) {
+ this.particles.push(this.createParticle(x, y));
+ }
+ }
+
+ animate() {
+ const canvas = document.createElement('canvas');
+ const ctx = canvas.getContext('2d');
+
+ canvas.style.position = 'fixed';
+ canvas.style.top = '0';
+ canvas.style.left = '0';
+ canvas.style.pointerEvents = 'none';
+ canvas.style.zIndex = '1000';
+
+ if (!document.body.contains(canvas)) {
+ document.body.appendChild(canvas);
+ }
+
+ canvas.width = window.innerWidth;
+ canvas.height = window.innerHeight;
+
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ this.particles.forEach((p, index) => {
+ p.x += p.speedX;
+ p.y += p.speedY;
+ p.speedY += 0.5;
+ p.rotation += p.rotationSpeed;
+
+ ctx.save();
+ ctx.translate(p.x, p.y);
+ ctx.rotate((p.rotation * Math.PI) / 180);
+ ctx.fillStyle = p.color;
+ ctx.fillRect(-p.size / 2, -p.size / 2, p.size, p.size);
+ ctx.restore();
+
+ if (p.y > window.innerHeight + p.size) {
+ this.particles.splice(index, 1);
+ }
+ });
+
+ window.requestAnimationFrame(this.animate.bind(this));
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => new Confetti());