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.0 KiB
JavaScript
1 line
2.0 KiB
JavaScript
!function(){const e=["😀","😂","😆","😊"];let t=document.body,i=window.innerWidth,n=window.innerHeight;const o={x:i/2,y:i/2},h={x:i/2,y:i/2};let a=0;const s=[],c=[];let d,l;function r(e){if(0<e.touches.length)for(let t=0;t<e.touches.length;t++)p(e.touches[t].clientX,e.touches[t].clientY,c[Math.floor(Math.random()*c.length)])}function p(t,e,i){s.push(new u(t,e,i))}function u(t,e,i){var n=Math.floor(60*Math.random()+80);this.initialLifeSpan=n,this.lifeSpan=n,this.velocity={x:(Math.random()<.5?-1:1)*(Math.random()/2),y:.4*Math.random()+.8},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+=.05;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"),l=d.getContext("2d"),d.style.top="0px",d.style.left="0px",d.style.pointerEvents="none",d.style.position="fixed",document.body.appendChild(d),d.width=i,d.height=n,l.font="21px serif",l.textBaseline="middle",l.textAlign="center",e.forEach(t=>{var e=l.measureText(t),i=document.createElement("canvas"),n=i.getContext("2d");i.width=e.width,i.height=2*e.actualBoundingBoxAscent,n.textAlign="center",n.font="21px serif",n.textBaseline="middle",n.fillText(t,i.width/2,e.actualBoundingBoxAscent),c.push(i)}),t.addEventListener("mousemove",function(t){t.timeStamp-a<16||window.requestAnimationFrame(()=>{o.x=t.clientX,o.y=t.clientY,1<Math.hypot(o.x-h.x,o.y-h.y)&&(p(o.x,o.y,c[Math.floor(Math.random()*e.length)]),h.x=o.x,h.y=o.y,a=t.timeStamp)})},{passive:!0}),t.addEventListener("touchmove",r,{passive:!0}),t.addEventListener("touchstart",r,{passive:!0}),window.addEventListener("resize",function(t){i=window.innerWidth,n=window.innerHeight,d.width=i,d.height=n}),function t(){l.clearRect(0,0,i,n);for(let t=0;t<s.length;t++)s[t].update(l);for(let t=s.length-1;0<=t;t--)s[t].lifeSpan<0&&s.splice(t,1);requestAnimationFrame(t)}()}(); |