Firefly Chandelier - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Firefly Chandelier</title> <style> body { margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #2c3e50; } canvas { background-color: #34495e; } </style> </head> <body> <canvas id="fireflyChandelier"></canvas> <script> const canvas = document.getElementById('fireflyChandelier'); const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; const chandelier = { lines: [], numberOfLines: 25, maxLength: 250 }; for (let i = 0; i < chandelier.numberOfLines; i++) { chandelier.lines.push({ x: canvas.width / 2 - chandelier.numberOfLines * 10 + i * 20, y: 100, length: Math.random() * chandelier.maxLength, flickerSpeed: Math.random() * 0.1 + 0.05, flicker: Math.random() * 10 }); } function drawChandelier() { ctx.clearRect(0, 0, canvas.width, canvas.height); chandelier.lines.forEach(line => { line.flicker += line.flickerSpeed; const endX = line.x; const endY = line.y + line.length * Math.sin(line.flicker); ctx.strokeStyle = '#fff'; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(line.x, line.y); ctx.lineTo(endX, endY); ctx.stroke(); drawLightBulb(endX, endY); }); } function drawLightBulb(x, y) { ctx.fillStyle = 'rgba(255, 223, 0, 0.8)'; ctx.beginPath(); ctx.arc(x, y, 10, 0, Math.PI * 2); ctx.fill(); } function animate() { drawChandelier(); requestAnimationFrame(animate); } animate(); </script> </body> </html>