mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-16 04:19:41 +08:00
1 line
2.5 KiB
JavaScript
1 line
2.5 KiB
JavaScript
(()=>{function t(t){this.maxFlake=(t=t||{}).maxFlake||10,this.flakeSize=t.flakeSize||10,this.fallSpeed=t.fallSpeed||1}const s=DreamConfig.effects_snowflake_mode;let n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame||function(t){setTimeout(t,1e3/60)};function h(t,e,i,a){this.x=Math.floor(Math.random()*t),this.y=Math.floor(Math.random()*e),this.size=Math.random()*i+2,this.maxSize=i,this.speed=+Math.random()+a,this.fallSpeed=a,this.velY=this.speed,this.velX=0,this.stepSize=Math.random()/30,this.step=0}function o(){var t=document.documentElement.classList.contains("night");if("all"===s||"day"===s&&!t||"night"===s&&t){var e=this.maxFlake,i=this.flakes;ctx=this.ctx,canvas=this.canvas,ctx.clearRect(0,0,canvas.width,canvas.height);for(var a=0;a<e;a++)i[a].update(),i[a].render(ctx)}(that=this).loop=n(function(){o.apply(that)})}window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame||window.oCancelAnimationFrame,t.prototype.start=function(){(function(){var t=document.createElement("canvas");t.id="snowfall",t.width=document.body.offsetWidth,t.height=window.innerHeight,t.setAttribute("class","canvas_effects "+s),t.setAttribute("style","z-index: 9999;"),document.getElementsByTagName("body")[0].appendChild(t),this.canvas=t,this.ctx=t.getContext("2d"),window.onresize=function(){t.width=document.body.offsetWidth,t.height=window.innerHeight}}).apply(this),function(){for(var t=this.maxFlake,e=this.flakes=[],i=this.canvas,a=0;a<t;a++)e.push(new h(i.width,i.height,this.flakeSize,this.fallSpeed))}.apply(this),o.apply(this)},h.prototype.update=function(){this.x,this.y,this.velX*=.98,this.velY<=this.speed&&(this.velY=this.speed),this.velX+=Math.cos(this.step+=.05)*this.stepSize,this.y+=this.velY,this.x+=this.velX,(this.x>=canvas.width||this.x<=0||this.y>=canvas.height||this.y<=0)&&this.reset(canvas.width,canvas.height)},h.prototype.reset=function(t,e){this.x=Math.floor(Math.random()*t),this.y=0,this.size=Math.random()*this.maxSize+2,this.speed=+Math.random()+this.fallSpeed,this.velY=this.speed,this.velX=0},h.prototype.render=function(t){var e=t.createRadialGradient(this.x,this.y,0,this.x,this.y,this.size);e.addColorStop(0,"rgba(255, 255, 255, 0.9)"),e.addColorStop(.5,"rgba(255, 255, 255, 0.5)"),e.addColorStop(1,"rgba(255, 255, 255, 0)"),t.save(),t.fillStyle=e,t.beginPath(),t.arc(this.x,this.y,this.size,0,2*Math.PI),t.fill(),t.restore()},new t({maxFlake:150}).start()})(); |