document.addEventListener('DOMContentLoaded', () => { const canvas = document.createElement('canvas'); canvas.id = 'particles-canvas'; document.body.insertBefore(canvas, document.body.firstChild); const ctx = canvas.getContext('2d'); let width, height; let particles = []; function resize() { width = canvas.width = window.innerWidth; height = canvas.height = window.innerHeight; } window.addEventListener('resize', resize); resize(); class Particle { constructor() { this.x = Math.random() * width; this.y = Math.random() * height; this.vx = (Math.random() - 0.5) * 0.5; this.vy = (Math.random() - 0.5) * 0.5; this.size = Math.random() * 2 + 0.5; } update() { this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > width) this.vx *= -1; if (this.y < 0 || this.y > height) this.vy *= -1; } draw() { ctx.beginPath(); ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2); ctx.fillStyle = 'rgba(124, 58, 237, 0.4)'; ctx.fill(); } } for(let i = 0; i < 50; i++) particles.push(new Particle()); function animate() { ctx.clearRect(0, 0, width, height); for(let i = 0; i < particles.length; i++) { particles[i].update(); particles[i].draw(); for(let j = i + 1; j < particles.length; j++) { const dx = particles[i].x - particles[j].x; const dy = particles[i].y - particles[j].y; const dist = Math.sqrt(dx*dx + dy*dy); if (dist < 150) { ctx.beginPath(); ctx.moveTo(particles[i].x, particles[i].y); ctx.lineTo(particles[j].x, particles[j].y); ctx.strokeStyle = `rgba(124, 58, 237, ${0.15 - dist/1000})`; ctx.stroke(); } } } requestAnimationFrame(animate); } animate(); });