Rainbow Glow 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>Rainbow Glow Chandelier</title> <style> body { margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #2980b9; } canvas { background-color: #ecf0f1; } </style> </head> <body> <canvas id="rainbowGlowCanvas"></canvas> <script> const canvas = document.getElementById('rainbowGlowCanvas'); const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; const chandelier = { lines: [], numberOfLines: 20, maxLength: 150, swingSpeed: 0.05, }; const colors = ['#e74c3c', '#f39c12', '#27ae60', '#2980b9', '#8e44ad']; 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, swingAngle: Math.random() * Math.PI * 2, color: colors[i % colors.length], glow: Math.random() * 0.5 + 0.5 }); } function drawChandelier() { ctx.clearRect(0, 0, canvas.width, canvas.height); chandelier.lines.forEach(line => { const swing = Math.sin(line.swingAngle) * 0.2; const endX = line.x + line.length * Math.sin(swing); const endY = line.y + line.length * Math.cos(swing); ctx.strokeStyle = line.color; ctx.lineWidth = 4; ctx.beginPath(); ctx.moveTo(line.x, line.y); ctx.lineTo(endX, endY); ctx.stroke(); drawLightBulb(endX, endY, line.color, line.glow); line.swingAngle += chandelier.swingSpeed; }); } function drawLightBulb(x, y, color, glow) { ctx.fillStyle = `rgba(255, 255, 0, ${glow})`; ctx.beginPath(); ctx.arc(x, y, 12, 0, Math.PI * 2); ctx.fill(); } function animate() { drawChandelier(); requestAnimationFrame(animate); } animate(); </script> </body> </html>