mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-17 07:09:40 +08:00
1 line
2.3 KiB
JavaScript
1 line
2.3 KiB
JavaScript
!function(){let n,o,t,e=document.body,s=10,c=10,h=window.innerWidth,y=window.innerHeight,l={x:h/2,y:h/2},a=[];function d(i){h=window.innerWidth,y=window.innerHeight,n.width=h,n.height=y}function x(i){0<i.touches.length&&(l.x=i.touches[0].clientX,l.y=i.touches[0].clientY)}function v(i){l.x=i.clientX,l.y=i.clientY}function r(){for(n.width=n.width,a[0].position.x=l.x,a[0].position.y=l.y,i=1;i<7;i++){var t=new p(0,0);0<i&&w(i-1,i,t),i<6&&w(i+1,i,t);var e=new p(10*-a[i].velocity.x,10*-a[i].velocity.y),t=new p(+(t.X+e.X),+(t.Y+e.Y)+50);a[i].velocity.x+=.01*t.X,a[i].velocity.y+=.01*t.Y,Math.abs(a[i].velocity.x)<.1&&Math.abs(a[i].velocity.y)<.1&&Math.abs(t.X)<.1&&Math.abs(t.Y)<.1&&(a[i].velocity.x=0,a[i].velocity.y=0),a[i].position.x+=a[i].velocity.x,a[i].position.y+=a[i].velocity.y,e=n.clientHeight,t=n.clientWidth,a[i].position.y>=e-11-1&&(0<a[i].velocity.y&&(a[i].velocity.y=.7*-a[i].velocity.y),a[i].position.y=e-11-1),a[i].position.x>=t-11&&(0<a[i].velocity.x&&(a[i].velocity.x=.7*-a[i].velocity.x),a[i].position.x=t-11-1),a[i].position.x<0&&(a[i].velocity.x<0&&(a[i].velocity.x=.7*-a[i].velocity.x),a[i].position.x=0),a[i].draw(o)}requestAnimationFrame(r)}function p(i,t){this.X=i,this.Y=t}function w(i,t,e){var n,o=a[i].position.x-a[t].position.x,i=a[i].position.y-a[t].position.y,t=Math.sqrt(o*o+i*i);t>s&&(n=c*(t-s),e.X+=o/t*n,e.Y+=i/t*n)}function u(i){this.position={x:l.x,y:l.y},this.velocity={x:0,y:0},this.canv=i,this.draw=function(i){i.drawImage(this.canv,this.position.x-this.canv.width/2,this.position.y-this.canv.height/2,this.canv.width,this.canv.height)}}{n=document.createElement("canvas"),o=n.getContext("2d"),n.style.top="0px",n.style.left="0px",n.style.pointerEvents="none",n.style.position="fixed",document.body.appendChild(n),n.width=h,n.height=y,o.font="16px serif",o.textBaseline="middle",o.textAlign="center";var f=o.measureText("🤪"),g=document.createElement("canvas"),m=g.getContext("2d");g.width=f.width,g.height=2*f.actualBoundingBoxAscent,m.textAlign="center",m.font="16px serif",m.textBaseline="middle",m.fillText("🤪",g.width/2,f.actualBoundingBoxAscent),t=g;let i=0;for(i=0;i<7;i++)a[i]=new u(t);e.addEventListener("mousemove",v),e.addEventListener("touchmove",x,{passive:!0}),e.addEventListener("touchstart",x,{passive:!0}),window.addEventListener("resize",d),r()}}(); |