| 1 | (function(){ |
| 2 | window.HPX = window.HPX || {}; |
| 3 | window.HPX['galaxy-swirl'] = function(el){ |
| 4 | const U = window.HPX._u; |
| 5 | const k = U.canvas(el), ctx = k.ctx; |
| 6 | const pal = U.palette(el); |
| 7 | const N = 800; |
| 8 | const parts = Array.from({length:N}, (_,i) => { |
| 9 | const arm = i%3; |
| 10 | const t = Math.random(); |
| 11 | const r = t*180 + 8; |
| 12 | const base = (arm/3)*Math.PI*2; |
| 13 | return { r, a: base + Math.log(r+1)*1.6 + U.rand(-0.2,0.2), |
| 14 | c: pal[arm%pal.length], |
| 15 | s: U.rand(0.8, 2.2) }; |
| 16 | }); |
| 17 | const stop = U.loop((t) => { |
| 18 | ctx.fillStyle = 'rgba(0,0,0,0.15)'; |
| 19 | ctx.fillRect(0,0,k.w,k.h); |
| 20 | const cx=k.w/2, cy=k.h/2; |
| 21 | for (const p of parts){ |
| 22 | const a = p.a + t*0.15; |
| 23 | const x = cx + Math.cos(a)*p.r; |
| 24 | const y = cy + Math.sin(a)*p.r*0.7; |
| 25 | ctx.fillStyle = p.c; |
| 26 | ctx.globalAlpha = 0.7; |
| 27 | ctx.beginPath(); ctx.arc(x,y,p.s,0,Math.PI*2); ctx.fill(); |
| 28 | } |
| 29 | ctx.globalAlpha = 1; |
| 30 | }); |
| 31 | return { stop(){ stop(); k.destroy(); } }; |
| 32 | }; |
| 33 | })(); |
| 34 |