*/ (function() { const canvas = document.getElementById("vipCanvasBg"); const ctx = canvas.getContext("2d"); const wrapper = document.getElementById("vip-bg-wrapper");let w, h; let particles = []; let lightnings = []; let frame = 0;function resize() { w = canvas.width = window.innerWidth; h = canvas.height = window.innerHeight; createParticles(); // สร้างละอองใหม่เมื่อขนาดจอเปลี่ยน }window.addEventListener("resize", resize);function createParticles() { particles = []; // ปรับจำนวนละอองให้เหมาะกับความละเอียดหน้าจอ const count = Math.min(w / 12, 80); for (let i = 0; i < count; i++) { particles.push({ x: Math.random() * w, y: Math.random() * h, size: Math.random() * 1.2 + 0.3, speedY: -Math.random() * 0.3 - 0.05, opacity: Math.random(), blink: Math.random() * 0.015 + 0.005 }); } }class Lightning { constructor() { this.segments = []; this.x = Math.random() * w; this.life = 1.0; this.decay = Math.random() * 0.02 + 0.015; this.width = Math.random() * 0.8 + 0.5; this.createPath(); } createPath() { let curX = this.x; let curY = 0; const segmentsCount = 10; const stepY = h / segmentsCount; for (let i = 0; i < segmentsCount; i++) { let nextX = curX + (Math.random() - 0.5) * 50; let nextY = curY + stepY; this.segments.push({ x1: curX, y1: curY, x2: nextX, y2: nextY }); curX = nextX; curY = nextY; } } draw() { ctx.save(); ctx.globalAlpha = this.life * 0.4; ctx.strokeStyle = "#DAA520"; ctx.lineWidth = this.width; ctx.shadowBlur = 8; ctx.shadowColor = "#FFD700"; ctx.beginPath(); this.segments.forEach(s => { ctx.moveTo(s.x1, s.y1); ctx.lineTo(s.x2, s.y2); }); ctx.stroke(); ctx.restore(); this.life -= this.decay; } }function animate() { ctx.clearRect(0, 0, w, h);// วาดละอองดาว particles.forEach(p => { p.y += p.speedY; p.opacity += p.blink; if (p.opacity > 0.8 || p.opacity < 0.1) p.blink *= -1; if (p.y < -10) p.y = h + 10;ctx.globalAlpha = Math.max(0, p.opacity); ctx.fillStyle = "#FFD700"; ctx.beginPath(); ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2); ctx.fill(); });// สุ่มเกิดสายฟ้า if (frame % 250 === 0 || Math.random() < 0.003) { lightnings.push(new Lightning()); }lightnings.forEach((l, i) => { l.draw(); if (l.life <= 0) lightnings.splice(i, 1); });frame++; requestAnimationFrame(animate); }resize(); animate(); })();
error: Content is protected !!