Changed around line 1
+ class ConfettiParticle {
+ constructor() {
+ this.reset();
+ }
+
+ reset() {
+ this.x = Math.random() * window.innerWidth;
+ this.y = Math.random() * -100;
+ this.velocity = {
+ x: Math.random() * 6 - 3,
+ y: Math.random() * 3 + 7
+ };
+ this.rotation = Math.random() * 360;
+ this.rotationSpeed = Math.random() * 10 - 5;
+ this.size = Math.random() * 10 + 5;
+ this.color = `hsl(${Math.random() * 360}, 80%, 60%)`;
+ }
+
+ update() {
+ this.y += this.velocity.y;
+ this.x += this.velocity.x;
+ this.rotation += this.rotationSpeed;
+ this.velocity.y += 0.1;
+
+ if (this.y > window.innerHeight) {
+ this.reset();
+ }
+ }
+
+ draw(ctx) {
+ ctx.save();
+ ctx.translate(this.x, this.y);
+ ctx.rotate(this.rotation * Math.PI / 180);
+ ctx.fillStyle = this.color;
+ ctx.fillRect(-this.size / 2, -this.size / 2, this.size, this.size);
+ ctx.restore();
+ }
+ }
+
+ class ConfettiSystem {
+ constructor() {
+ this.canvas = document.createElement('canvas');
+ this.ctx = this.canvas.getContext('2d');
+ this.particles = [];
+ this.isActive = false;
+
+ this.canvas.style.position = 'fixed';
+ this.canvas.style.top = '0';
+ this.canvas.style.left = '0';
+ this.canvas.style.pointerEvents = 'none';
+ this.canvas.style.zIndex = '1000';
+ document.body.appendChild(this.canvas);
+
+ this.resize();
+ window.addEventListener('resize', () => this.resize());
+
+ for (let i = 0; i < 100; i++) {
+ this.particles.push(new ConfettiParticle());
+ }
+
+ this.bindEvents();
+ this.animate();
+ }
+
+ resize() {
+ this.canvas.width = window.innerWidth;
+ this.canvas.height = window.innerHeight;
+ }
+
+ bindEvents() {
+ document.addEventListener('click', () => this.burst());
+ document.addEventListener('scroll', () => {
+ if (!this.isActive) this.burst();
+ }, { passive: true });
+
+ document.getElementById('mainButton').addEventListener('click', (e) => {
+ e.stopPropagation();
+ this.burst(200);
+ });
+ }
+
+ burst(amount = 50) {
+ this.isActive = true;
+ setTimeout(() => this.isActive = false, 1000);
+
+ for (let i = 0; i < amount; i++) {
+ const particle = new ConfettiParticle();
+ particle.y = window.innerHeight / 2;
+ particle.x = window.innerWidth / 2;
+ this.particles.push(particle);
+ }
+ }
+
+ animate() {
+ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
+
+ this.particles.forEach(particle => {
+ particle.update();
+ particle.draw(this.ctx);
+ });
+
+ requestAnimationFrame(() => this.animate());
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new ConfettiSystem();
+ });