halo-theme-dream2.0-plus/source/js/cursor/move/fairyDustCursor.min.js
2023-03-21 10:49:35 +08:00

1 line
2.0 KiB
JavaScript

!function(){let e=["#D61C59","#E7D84B","#1B8798"],i=void 0,t=(i,document.body),n=window.innerWidth,o=window.innerHeight;const h={x:n/2,y:n/2},a={x:n/2,y:n/2},s=[],l=[];let d,c;function r(e){if(0<e.touches.length)for(let t=0;t<e.touches.length;t++)u(e.touches[t].clientX,e.touches[t].clientY,l[Math.floor(Math.random()*l.length)])}function u(t,e,i){s.push(new f(t,e,i))}function f(t,e,i){var n=Math.floor(30*Math.random()+60);this.initialLifeSpan=n,this.lifeSpan=n,this.velocity={x:(Math.random()<.5?-1:1)*(Math.random()/2),y:.7*Math.random()+.9},this.position={x:t,y:e},this.canv=i,this.update=function(t){this.position.x+=this.velocity.x,this.position.y+=this.velocity.y,this.lifeSpan--,this.velocity.y+=.02;var e=Math.max(this.lifeSpan/this.initialLifeSpan,0);t.drawImage(this.canv,this.position.x-this.canv.width/2*e,this.position.y-this.canv.height/2,this.canv.width*e,this.canv.height*e)}}d=document.createElement("canvas"),c=d.getContext("2d"),d.style.top="0px",d.style.left="0px",d.style.pointerEvents="none",i,d.style.position="fixed",t.appendChild(d),d.width=n,d.height=o,c.font="21px serif",c.textBaseline="middle",c.textAlign="center",e.forEach(t=>{var e=c.measureText("*"),i=document.createElement("canvas"),n=i.getContext("2d");i.width=e.width,i.height=e.actualBoundingBoxAscent+e.actualBoundingBoxDescent,n.fillStyle=t,n.textAlign="center",n.font="21px serif",n.textBaseline="middle",n.fillText("*",i.width/2,e.actualBoundingBoxAscent),l.push(i)}),t.addEventListener("mousemove",function(t){window.requestAnimationFrame(()=>{i;{const e=void 0}h.x=t.clientX,h.y=t.clientY,1.5<Math.hypot(h.x-a.x,h.y-a.y)&&(u(h.x,h.y,l[Math.floor(Math.random()*e.length)]),a.x=h.x,a.y=h.y)})}),t.addEventListener("touchmove",r,{passive:!0}),t.addEventListener("touchstart",r,{passive:!0}),window.addEventListener("resize",function(t){n=window.innerWidth,o=window.innerHeight,i,d.width=n,d.height=o}),function t(){c.clearRect(0,0,n,o);for(let t=0;t<s.length;t++)s[t].update(c);for(let t=s.length-1;0<=t;t--)s[t].lifeSpan<0&&s.splice(t,1);requestAnimationFrame(t)}()}();