Spiral Lights 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>Spiral Lights Chandelier</title> <style> body { margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #34495e; } canvas { background-color: #ecf0f1; } </style> </head> <body> <canvas id="spiralLightsCanvas"></canvas> <script> const canvas = document.getElementById('spiralLightsCanvas'); const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; const chandelier = { lines: [], numberOfLines: 30, maxLength: 200, angleIncrement: 0.1, radius: 50 }; for (let i = 0; i < chandelier.numberOfLines; i++) { chandelier.lines.push({ angle: i * (Math.PI / 15), length: Math.random() * chandelier.maxLength, color: `hsl(${Math.random() * 360}, 100%, 50%)` }); } function drawChandelier() { ctx.clearRect(0, 0, canvas.width, canvas.height); chandelier.lines.forEach((line, index) => { line.angle += chandelier.angleIncrement; const x = canvas.width / 2 + chandelier.radius * Math.cos(line.angle); const y = canvas.height / 2 + chandelier.radius * Math.sin(line.angle); ctx.strokeStyle = line.color; ctx.lineWidth = 4; ctx.beginPath(); ctx.moveTo(canvas.width / 2, canvas.height / 2); ctx.lineTo(x, y); ctx.stroke(); drawLightBulb(x, y, line.color); }); } function drawLightBulb(x, y, color) { ctx.fillStyle = color; ctx.beginPath(); ctx.arc(x, y, 10, 0, Math.PI * 2); ctx.fill(); } function animate() { drawChandelier(); requestAnimationFrame(animate); } animate(); </script> </body> </html>