2023-03-21 10:49:35 +08:00

1 line
2.0 KiB
JavaScript

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