-
Notifications
You must be signed in to change notification settings - Fork 8
/
background.min.js
1 lines (1 loc) · 4.56 KB
/
background.min.js
1
window.addEventListener("load",function(){function e(e,t,n){return n*(t-e)+e}function t(e){return e<0?0:e>1?1:e}function n(e){return Math.random()*(e.max-e.min)+e.min}function o(){return new a(n(g.gradient.hue),n(g.gradient.saturation),n(g.gradient.lightness))}function s(){return f.force||navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)}function a(e,t,n){this.h=e,this.s=t,this.l=n,this.str=function(){return this.h+", "+this.s+"%, "+this.l+"%"}}function r(t,n,o){this.x=t,this.y=n,this.oldColor=o,this.newColor=o,this.step=0,this.speed=0,this.color=function(){return new a(e(this.oldColor.h,this.newColor.h,this.step),e(this.oldColor.s,this.newColor.s,this.step),e(this.oldColor.l,this.newColor.l,this.step))}}function h(t,n,o,i){this.oldX=t,this.oldY=n,this.oldSize=o,this.oldAlpha=i,this.newX=0,this.newY=0,this.newAlpha=0,this.newSize=0,this.step=0,this.speed=0,this.x=function(){return e(this.oldX,this.newX,this.step)},this.y=function(){return e(this.oldY,this.newY,this.step)},this.alpha=function(){return e(this.oldAlpha,this.newAlpha,this.step)},this.size=function(){return e(this.oldSize,this.newSize,this.step)}}function l(e){e.newX=t(e.oldX+n({min:-g.bokeh.jitter.x,max:g.bokeh.jitter.x})),e.newY=t(e.oldY+n({min:-g.bokeh.jitter.y,max:g.bokeh.jitter.y}))}function d(){var e=window.innerWidth,t=window.innerHeight;y=e*g.resolution,z=t*g.resolution,S=Math.sqrt(y*z),p.canvas.width=e,p.canvas.height=t,p.scale(1/g.resolution,1/g.resolution);var n=g.bokeh.size.max*S;b.canvas.width=2*n+1,b.canvas.height=2*n+1,b.fillStyle="rgb(255, 255, 255)",b.beginPath(),b.arc(n,n,n,0,E),b.closePath(),b.fill(),s()&&c()}function u(e,t){var n=0;for(var o in e)t.hasOwnProperty(o)&&0==u(e[o],t[o])&&(t[o]=e[o]),n++;return n}function w(){var e=Date.now();k+=e-(m||e),x++;var t=(e-(m||e))/(1e3/A);m=e,k>1e3&&(C=1e3/(k/x),k-=1e3,x=0),F.forEach(function(e){e.step+=e.speed*t,e.step>=1&&(e.step=0,e.oldColor=e.newColor,e.newColor=o(),e.speed=n(g.speed))}),R.forEach(function(e){e.step+=e.speed*t,e.step>=1&&(e.step=0,e.oldX=e.newX,e.oldY=e.newY,e.oldAlpha=e.newAlpha,e.oldSize=e.newSize,l(e),e.newAlpha=n(g.bokeh.alpha),e.newSize=n(g.bokeh.size),e.speed=n(g.speed))})}function c(){w(),F.forEach(function(e){var t=e.x*g.gradient.resolution,n=e.y*g.gradient.resolution,o=v.createRadialGradient(t,n,g.gradient.smallRadius,t,n,g.gradient.resolution);o.addColorStop(0,"hsla("+e.color().str()+", 255)"),o.addColorStop(1,"hsla("+e.color().str()+", 0)"),v.fillStyle=o,v.fillRect(0,0,g.gradient.resolution,g.gradient.resolution)}),p.globalCompositeOperation="source-over",p.drawImage(v.canvas,0,0,y,z),p.globalCompositeOperation="overlay",g.debug.strokeBokeh&&(p.strokeStyle="yellow"),R.forEach(function(e){var t=e.size()*S;p.globalAlpha=e.alpha(),p.drawImage(b.canvas,e.x()*y-t/2,e.y()*z-t/2,t,t),g.debug.strokeBokeh&&(p.globalAlpha=1,p.globalCompositeOperation="source-over",p.strokeRect(e.x()*y-t/2,e.y()*z-t/2,t,t),p.globalCompositeOperation="overlay")}),p.globalAlpha=1,g.debug.showFps&&(p.fillStyle=C<=10?"red":"yellow",p.font="20px sans-serif",p.fillText(Math.round(C)+" fps",10,20)),window.requestAnimFrame(c)}var m,p=document.getElementById("background").getContext("2d"),g={resolution:1,gradient:{resolution:4,smallRadius:0,hue:{min:0,max:360},saturation:{min:40,max:80},lightness:{min:25,max:35}},bokeh:{count:30,size:{min:.1,max:.3},alpha:{min:.05,max:.4},jitter:{x:.3,y:.3}},speed:{min:1e-4,max:.001},debug:{strokeBokeh:!1,showFps:!1}},f={force:!1,resolution:.5,bokeh:{count:6}},v=document.createElement("canvas").getContext("2d"),b=document.createElement("canvas").getContext("2d"),A=60,k=0,x=0,C=0,y=0,z=0,S=0,E=2*Math.PI;window.requestAnimFrame=function(e){return s()?function(e){window.setTimeout(e,100)}:window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}();var F=[new r(0,0,new a(196,59,34)),new r(0,1,new a(269,79,32)),new r(1,0,new a(30,42,33)),new r(1,1,new a(304,47,27))],R=[];window.addEventListener("resize",d),function(){for(v.canvas.height=g.gradient.resolution,v.canvas.width=g.gradient.resolution,s()&&u(f,g),d(),F.forEach(function(e){e.oldColor=o(),e.newColor=o(),e.speed=n(g.speed)}),i=0;i<g.bokeh.count;i++)R.push(new h(Math.random(),Math.random(),n(g.bokeh.size),n(g.bokeh.alpha))),R[i].newAlpha=n(g.bokeh.alpha),R[i].newSize=n(g.bokeh.size),R[i].speed=n(g.speed),l(R[i])}(),c()});