1
0
mirror of https://github.com/StarGazer114/stargazer114.github.io.git synced 2025-01-09 23:08:16 +08:00
stargazer114.github.io/pluginsSrc/butterfly-extsrc/dist/canvas-ribbon.min.js

1 line
1.2 KiB
JavaScript
Raw Normal View History

2025-01-05 20:41:38 +08:00
(()=>{const e=document.getElementById("ribbon"),t=/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent);if("false"===e.getAttribute("mobile")&&t)return;const i=(e,t,i)=>Number(e.getAttribute(t))||i,n={zIndex:i(e,"zIndex",-1),alpha:i(e,"alpha",.6),size:i(e,"size",90),clickToRedraw:"false"!==e.getAttribute("data-click")},o=document.createElement("canvas"),a=o.getContext("2d"),{devicePixelRatio:c=1}=window,{innerWidth:l,innerHeight:d}=window,r=n.size;o.width=l*c,o.height=d*c,a.scale(c,c),a.globalAlpha=n.alpha,o.style.cssText=`opacity: ${n.alpha}; position: fixed; top: 0; left: 0; z-index: ${n.zIndex}; width: 100%; height: 100%; pointer-events: none;`,document.body.appendChild(o);let h=[{x:0,y:.7*d+r},{x:0,y:.7*d-r}],s=0;const x=2*Math.PI,y=e=>{const t=e+(2*Math.random()-1.1)*r;return t>d||t<0?y(e):t},g=(e,t)=>{a.beginPath(),a.moveTo(e.x,e.y),a.lineTo(t.x,t.y);const i=t.x+(2*Math.random()-.25)*r,n=y(t.y);a.lineTo(i,n),a.closePath(),s-=x/-50,a.fillStyle="#"+(127*Math.cos(s)+128<<16|127*Math.cos(s+x/3)+128<<8|127*Math.cos(s+x/3*2)+128).toString(16),a.fill(),h[0]=h[1],h[1]={x:i,y:n}},u=()=>{for(a.clearRect(0,0,l,d),h=[{x:0,y:.7*d+r},{x:0,y:.7*d-r}];h[1].x<l+r;)g(h[0],h[1])};n.clickToRedraw&&(document.onclick=u,document.ontouchstart=u),u()})();