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(){let e,o,t=document.body,i=["❄️"],n=window.innerWidth,a=window.innerHeight,h={x:n/2,y:n/2},s=[],l=[];function d(e){if(0<e.touches.length)for(let t=0;t<e.touches.length;t++)c(e.touches[t].clientX,e.touches[t].clientY,l[Math.floor(Math.random()*l.length)])}function c(t,e,i){s.push(new r(t,e,i))}function r(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",e.style.position="fixed",document.body.appendChild(e),e.width=n,e.height=a,o.font="12px serif",o.textBaseline="middle",o.textAlign="center",i.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){h.x=t.clientX,h.y=t.clientY,c(h.x,h.y,l[Math.floor(Math.random()*i.length)])}),t.addEventListener("touchmove",d,{passive:!0}),t.addEventListener("touchstart",d,{passive:!0}),window.addEventListener("resize",function(t){n=window.innerWidth,a=window.innerHeight,e.width=n,e.height=a}),function t(){o.clearRect(0,0,n,a);for(let t=0;t<s.length;t++)s[t].update(o);for(let t=s.length-1;0<=t;t--)s[t].lifeSpan<0&&s.splice(t,1);requestAnimationFrame(t)}()}(); |