// Quantum Particle Field Animation class QuantumParticleField { constructor() { this.canvas = document.getElementById('quantum-canvas'); this.ctx = this.canvas.getContext('2d'); this.particles = []; this.connections = []; this.mouse = { x: 0, y: 0 }; this.init(); this.animate(); this.setupEventListeners(); } init() { this.resizeCanvas(); this.createParticles(); } resizeCanvas() { this.canvas.width = window.innerWidth; this.canvas.height = window.innerHeight; } createParticles() { const particleCount = Math.min(100, Math.floor(window.innerWidth * window.innerHeight / 15000)); this.particles = []; const colors = [ { r: 6, g: 182, b: 212 }, // Cyan { r: 59, g: 130, b: 246 }, // Blue { r: 139, g: 92, b: 246 }, // Purple { r: 236, g: 72, b: 153 }, // Pink { r: 249, g: 115, b: 22 } // Orange ]; for (let i = 0; i < particleCount; i++) { const color = colors[Math.floor(Math.random() * colors.length)]; const alpha = Math.random() * 0.6 + 0.4; // Higher opacity for better visibility this.particles.push({ x: Math.random() * this.canvas.width, y: Math.random() * this.canvas.height, vx: (Math.random() - 0.5) * 0.3, // Slower movement vy: (Math.random() - 0.5) * 0.3, radius: Math.random() * 4 + 2, // Larger particles color: `rgba(${color.r}, ${color.g}, ${color.b}, ${alpha})`, originalRadius: Math.random() * 4 + 2, glow: Math.random() * 0.8 + 0.7, // Stronger glow connections: [] }); } } drawParticles() { this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); // Draw connections first this.drawConnections(); // Draw particles this.particles.forEach(particle => { this.ctx.beginPath(); this.ctx.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2); // Enhanced glowing effect with stronger visibility const gradient = this.ctx.createRadialGradient( particle.x, particle.y, 0, particle.x, particle.y, particle.radius * 4 ); gradient.addColorStop(0, particle.color.replace(')', ', 1)').replace('rgba', 'rgb')); gradient.addColorStop(0.3, particle.color); gradient.addColorStop(1, 'rgba(0, 0, 0, 0)'); this.ctx.fillStyle = gradient; this.ctx.fill(); // Add outer glow this.ctx.beginPath(); this.ctx.arc(particle.x, particle.y, particle.radius * 3, 0, Math.PI * 2); const outerGradient = this.ctx.createRadialGradient( particle.x, particle.y, particle.radius, particle.x, particle.y, particle.radius * 3 ); outerGradient.addColorStop(0, particle.color.replace(')', ', 0.3)')); outerGradient.addColorStop(1, 'rgba(0, 0, 0, 0)'); this.ctx.fillStyle = outerGradient; this.ctx.fill(); // Pulsing effect particle.radius = particle.originalRadius + Math.sin(Date.now() * 0.001 + particle.x) * 0.8; }); } drawConnections() { const maxDistance = 120; for (let i = 0; i < this.particles.length; i++) { for (let j = i + 1; j < this.particles.length; j++) { const dx = this.particles[i].x - this.particles[j].x; const dy = this.particles[i].y - this.particles[j].y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < maxDistance) { const opacity = 1 - (distance / maxDistance); // Create gradient for connection line const gradient = this.ctx.createLinearGradient( this.particles[i].x, this.particles[i].y, this.particles[j].x, this.particles[j].y ); gradient.addColorStop(0, this.particles[i].color); gradient.addColorStop(1, this.particles[j].color); this.ctx.beginPath(); this.ctx.strokeStyle = gradient; this.ctx.lineWidth = opacity * 1.5; this.ctx.globalAlpha = opacity * 0.3; this.ctx.moveTo(this.particles[i].x, this.particles[i].y); this.ctx.lineTo(this.particles[j].x, this.particles[j].y); this.ctx.stroke(); this.ctx.globalAlpha = 1; } } } } updateParticles() { this.particles.forEach(particle => { // Move particle particle.x += particle.vx; particle.y += particle.vy; // Bounce off walls if (particle.x < 0 || particle.x > this.canvas.width) particle.vx *= -1; if (particle.y < 0 || particle.y > this.canvas.height) particle.vy *= -1; // Mouse interaction const dx = particle.x - this.mouse.x; const dy = particle.y - this.mouse.y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < 100) { const force = (100 - distance) / 100; particle.vx += dx * force * 0.01; particle.vy += dy * force * 0.01; } // Apply friction particle.vx *= 0.99; particle.vy *= 0.99; }); } animate() { this.updateParticles(); this.drawParticles(); requestAnimationFrame(() => this.animate()); } setupEventListeners() { window.addEventListener('resize', () => { this.resizeCanvas(); this.createParticles(); }); window.addEventListener('mousemove', (e) => { this.mouse.x = e.clientX; this.mouse.y = e.clientY; }); // Touch support for mobile window.addEventListener('touchmove', (e) => { this.mouse.x = e.touches[0].clientX; this.mouse.y = e.touches[0].clientY; }); } } // Initialize when DOM is loaded document.addEventListener('DOMContentLoaded', () => { new QuantumParticleField(); }); // Additional utility functions function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; }