-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetSchwifty.min.js
executable file
·1 lines (1 loc) · 2.8 KB
/
GetSchwifty.min.js
1
!function(){for(var t=0,i=["ms","moz","webkit","o"],e=0;e<i.length&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[i[e]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[i[e]+"CancelAnimationFrame"]||window[i[e]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(i,e){var n=(new Date).getTime(),h=Math.max(0,16-(n-t)),o=window.setTimeout(function(){i(n+h)},h);return t=n+h,o}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)}),this.GetSchwifty=function(){function t(t,i){var e;for(e in i)i.hasOwnProperty(e)&&(t[e]=i[e]);return t}var i={selector:"canvas",rowPieces:8,columnPieces:8,yUpdateSpeed:50,xUpdateSpeed:50,width:window.innerWidth,height:window.innerHeight};arguments[0]&&"object"==typeof arguments[0]&&(this.options=t(i,arguments[0]));var e,n,h=document.querySelector(this.options.selector),o=h.getContext("2d"),s=new Image,r=this.options.rowPieces,a=this.options.columnPieces,w=r*a,d=0,c=this.options.yUpdateSpeed,m=this.options.xUpdateSpeed,u=[],f=[],g=!0,y=!0,l=[],p=!1,x=!1;s.src=this.options.img,h.width=this.options.width,h.height=this.options.height,s.onload=function(){function t(){for(var t=1,e=0;e<a;e++)for(var n=0;n<r;n++)u.push(new i(h.width/r,s.width/r,h.height/a,s.height/a,s.width/r*n,s.width/r*n,0,h.width/r*n,h.width/r,h.width/r*n,s.height/a*e,s.height/a*e,0,h.height/a*e,h.height/a,h.height/a*e,t)),t++}function i(t,i,e,n,h,o,s,r,a,w,d,c,m,u,f,g,y){this.w=t,this.sWidth=i,this.h=e,this.sHeight=n,this.sx=h,this.fromSx=o,this.toSx=s,this.x=-r,this.fromX=a,this.toX=w,this.sy=d,this.fromSy=c,this.toSy=m,this.y=-u,this.fromY=f,this.toY=g,this.i=y,this.axisYFullyReset=!1,this.axisXFullyReset=!1}function S(){if(startSySxAnimationFunctionJustOnce===!0){u.reverse();for(var t=0;t<f.length-1;++t)f[t].toSy=u[t].fromSy,f[t].toSx=u[t].fromSx;x=!0}}function F(){n=setTimeout(function(){e=window.requestAnimationFrame(F),f.length<=u.length&&(f.push(u[d]),d<=w?d+=1:d=0),o.clearRect(0,0,h.width,h.height);for(var t=0;t<f.length;++t){if(u[u.length-1].x!=u[u.length-1].toX||u[u.length-1].y!=u[u.length-1].toY?g=!0:y===!0&&(setTimeout(function(){startSySxAnimationFunctionJustOnce=!0,S()},2e3),y=!1),l.length===u.length){for(var i=0;i<l.length;i++){if(l[i].x===!1||l[i].y===!1){p=!0;break}i===l.length-1&&(p=!0)}if(p===!0){g=!1;break}}g===!0?"undefined"!=typeof f[t]&&(f[t].update(),f[t].render()):e&&window.cancelAnimationFrame(e)}},1e3/60)}t(),i.prototype.update=function(){this.y<this.toY&&(this.y+=c),this.y>this.toY&&(this.y=this.toY),this.x<this.toX&&(this.x+=m),this.x>this.toX&&(this.x=this.toX),x===!0&&(this.sy<this.toSy?this.sy+=c:this.sy=this.toSy,this.sx<this.toSx?this.sx+=m:this.sx=this.toSx)},i.prototype.render=function(){o.drawImage(s,this.sx,this.sy,this.sWidth,this.sHeight,this.x,this.y,this.w,this.h)},F()}}}();