mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-15 02:43:08 +08:00
1 line
2.0 KiB
JavaScript
1 line
2.0 KiB
JavaScript
!function(){let e,o,i=void 0,t=(i,document.body),n=["❄️"],a=window.innerWidth,h=window.innerHeight,s={x:a/2,y:a/2},d=[],l=[];function c(e){if(0<e.touches.length)for(let t=0;t<e.touches.length;t++)r(e.touches[t].clientX,e.touches[t].clientY,l[Math.floor(Math.random()*l.length)])}function r(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:1+Math.random()},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.x+=2*(Math.random()<.5?-1:1)/75,this.velocity.y-=Math.random()/300;var e=Math.max(this.lifeSpan/this.initialLifeSpan,0),i=2*this.lifeSpan*.0174533;t.translate(this.position.x,this.position.y),t.rotate(i),t.drawImage(this.canv,-this.canv.width/2*e,-this.canv.height/2,this.canv.width*e,this.canv.height*e),t.rotate(-i),t.translate(-this.position.x,-this.position.y)}}e=document.createElement("canvas"),o=e.getContext("2d"),e.style.top="0px",e.style.left="0px",e.style.pointerEvents="none",i,e.style.position="fixed",document.body.appendChild(e),e.width=a,e.height=h,o.font="12px serif",o.textBaseline="middle",o.textAlign="center",n.forEach(t=>{var e=o.measureText(t),i=document.createElement("canvas"),n=i.getContext("2d");i.width=e.width,i.height=2*e.actualBoundingBoxAscent,n.textAlign="center",n.font="12px serif",n.textBaseline="middle",n.fillText(t,i.width/2,e.actualBoundingBoxAscent),l.push(i)}),t.addEventListener("mousemove",function(t){i,s.x=t.clientX,s.y=t.clientY,r(s.x,s.y,l[Math.floor(Math.random()*n.length)])}),t.addEventListener("touchmove",c,{passive:!0}),t.addEventListener("touchstart",c,{passive:!0}),window.addEventListener("resize",function(t){a=window.innerWidth,h=window.innerHeight,i,e.width=a,e.height=h}),function t(){o.clearRect(0,0,a,h);for(let t=0;t<d.length;t++)d[t].update(o);for(let t=d.length-1;0<=t;t--)d[t].lifeSpan<0&&d.splice(t,1);requestAnimationFrame(t)}()}(); |