-
Notifications
You must be signed in to change notification settings - Fork 0
/
weatherPlugin.min.js
1 lines (1 loc) · 3 KB
/
weatherPlugin.min.js
1
function weatherObj(t,s){this.el=t,this.dropDarkness=[],this.resize=0,this.settings={dropDensity:void 0===s.dropDensity?40:s.dropDensity,dropColor:void 0===s.dropColor?[0,0,0]:s.dropColor,speed:void 0===s.speed?10:s.speed,wind:void 0===s.wind?-5:s.wind,dropDarkness:void 0===s.dropDarkness?.5:s.dropDarkness,dropWidth:void 0===s.dropWidth?1:s.dropWidth,dropHeight:void 0===s.dropHeight?2:s.dropHeight};var n=this;this.functions={canvas:{init:function(){n.functions.general.overrideSettings(),n.functions.canvas.initCanvas(),n.functions.general.initDrops(),n.functions.general.drawloop()},initCanvas:function(){n.canvas=document.createElement("canvas"),n.canvas.className="w-canvas",n.canvas.style.position="absolute",n.canvas.style.top=0,n.canvas.style.left=0,n.canvas.setAttribute("aria-hidden","true"),n.el.style.position="relative",n.el.appendChild(n.canvas),n.context=n.canvas.getContext("2d"),n.functions.canvas.initialise()},initialise:function(){n.canvas.width=n.el.offsetWidth,n.canvas.height=n.el.offsetHeight},clearCanvas:function(){n.context.clearRect(0,0,n.canvas.width,n.canvas.height)}},general:{overrideSettings:function(){n.settings.wind>35&&(n.settings.wind=35),n.settings.wind<-35&&(n.settings.wind=-35),(n.settings.dropDarkness>1||n.settings.dropDarkness<0)&&(n.settings.dropDarkness=1),n.settings.dropColor.constructor===Array&&3===n.settings.dropColor.length||(n.settings.dropColor=[0,0,0])},initDrops:function(){var t=n.canvas.width/100*n.settings.dropDensity;n.minstart=-20,n.maxstop=n.canvas.height+20,n.spacing=n.canvas.width/t,n.drops=[];for(var s=0;s<t;s++)n.drops.push([n.spacing*s,n.functions.general.randomIntFromInterval(n.minstart,n.maxstop)]);n.dropDarkness.push(n.settings.dropDarkness),n.dropDarkness.push(n.settings.dropDarkness/3*2),n.dropDarkness.push(n.settings.dropDarkness/3)},randomIntFromInterval:function(t,s){return Math.floor(Math.random()*(s-t+1)+t)},resizeWindow:function(){n.functions.canvas.initialise(),n.functions.general.initDrops()},drawloop:function(){n.functions.canvas.clearCanvas();for(var t=.2,s=0,e=0;e<n.drops.length;e++)n.drops[e][1]=n.drops[e][1]+n.settings.speed+10*t,n.drops[e][1]>n.maxstop&&(n.drops[e][1]=n.minstart),n.context.save(),n.context.fillStyle="rgba("+n.settings.dropColor[0]+","+n.settings.dropColor[1]+","+n.settings.dropColor[2]+","+n.dropDarkness[s]+")",n.settings.wind?(n.drops[e][0]+=n.settings.wind/2,n.drops[e][0]>n.canvas.width&&(n.drops[e][0]=0),n.drops[e][0]<0&&(n.drops[e][0]=n.canvas.width),n.context.translate(n.drops[e][0],n.drops[e][1]),n.context.rotate(-n.settings.wind*Math.PI/90),n.context.fillRect(0,0,n.settings.dropWidth,n.settings.dropHeight+8*t)):n.context.fillRect(n.drops[e][0],n.drops[e][1],n.settings.dropWidth,n.settings.dropHeight+8*t),n.context.restore(),(t+=.2)>1&&(t=.2),(s+=1)>=n.dropDarkness.length&&(s=0);setTimeout(n.functions.general.drawloop,40)}}},window.addEventListener("load",function(){n.functions.canvas.init()},!1),window.addEventListener("resize",function(){clearTimeout(n.resize),n.resize=setTimeout(n.functions.general.resizeWindow,200)},!1)}