(function(){function t(t){this.converter=t.converter;this.data=t.path||t.data;this.imageData=[];this.multiplier=t.multiplier||1;this.padding=t.padding||0;this.fps=t.fps||25;this.stepsPerFrame=~~t.stepsPerFrame||1;this.trailLength=t.trailLength||1;this.pointDistance=t.pointDistance||.05;this.domClass=t.domClass||"sonic";this.backgroundColor=t.backgroundColor||"rgba(0,0,0,0)";this.fillColor=t.fillColor;this.strokeColor=t.strokeColor;this.stepMethod=typeof t.step=="string"?s[t.step]:t.step||s.square;this._setup=t.setup||e;this._teardown=t.teardown||e;this._preStep=t.preStep||e;this.pixelRatio=t.pixelRatio||null;this.width=t.width;this.height=t.height;this.fullWidth=this.width+2*this.padding;this.fullHeight=this.height+2*this.padding;this.domClass=t.domClass||"sonic";this.setup()}var e=function(){};var n=t.argTypes={DIM:1,DEGREE:2,RADIUS:3,OTHER:0};var r=t.argSignatures={arc:[1,1,3,2,2,0],bezier:[1,1,1,1,1,1,1,1],line:[1,1,1,1]};var i=t.pathMethods={bezier:function(e,t,n,r,i,s,o,u,a){e=1-e;var f=1-e,l=e*e,c=f*f,h=l*e,p=3*l*f,d=3*e*c,v=c*f;return[h*t+p*s+d*u+v*r,h*n+p*o+d*a+v*i]},arc:function(e,t,n,r,i,s){var o=(s-i)*e+i;var u=[Math.cos(o)*r+t,Math.sin(o)*r+n];u.angle=o;u.t=e;return u},line:function(e,t,n,r,i){return[(r-t)*e+t,(i-n)*e+n]}};var s=t.stepMethods={square:function(e,t,n,r,i){this._.fillRect(e.x-3,e.y-3,6,6)},fader:function(e,t,n,r,i){this._.beginPath();if(this._last){this._.moveTo(this._last.x,this._last.y)}this._.lineTo(e.x,e.y);this._.closePath();this._.stroke();this._last=e}};t.prototype={calculatePixelRatio:function(){var e=window.devicePixelRatio||1;var t=this._.webkitBackingStorePixelRatio||this._.mozBackingStorePixelRatio||this._.msBackingStorePixelRatio||this._.oBackingStorePixelRatio||this._.backingStorePixelRatio||1;return e/t},setup:function(){var e,t,s,o,u=this.data;this.canvas=document.createElement("canvas");this._=this.canvas.getContext("2d");if(this.pixelRatio==null){this.pixelRatio=this.calculatePixelRatio()}this.canvas.className=this.domClass;if(this.pixelRatio!=1){this.canvas.style.height=this.fullHeight+"px";this.canvas.style.width=this.fullWidth+"px";this.fullHeight*=this.pixelRatio;this.fullWidth*=this.pixelRatio;this.canvas.height=this.fullHeight;this.canvas.width=this.fullWidth;this._.scale(this.pixelRatio,this.pixelRatio)}else{this.canvas.height=this.fullHeight;this.canvas.width=this.fullWidth}this.points=[];for(var a=-1,f=u.length;++a<f;){e=u[a].slice(1);s=u[a][0];if(s in r)for(var l=-1,c=e.length;++l<c;){t=r[s][l];o=e[l];switch(t){case n.RADIUS:o*=this.multiplier;break;case n.DIM:o*=this.multiplier;o+=this.padding;break;case n.DEGREE:o*=Math.PI/180;break}e[l]=o}e.unshift(0);for(var h,p=this.pointDistance,d=p;d<=1;d+=p){d=Math.round(d*1/p)/(1/p);e[0]=d;h=i[s].apply(null,e);this.points.push({x:h[0],y:h[1],progress:d})}}this.frame=0;if(this.converter&&this.converter.setup){this.converter.setup(this)}},prep:function(e){if(e in this.imageData){return}this._.clearRect(0,0,this.fullWidth,this.fullHeight);this._.fillStyle=this.backgroundColor;this._.fillRect(0,0,this.fullWidth,this.fullHeight);var t=this.points,n=t.length,r=this.pointDistance,i,s,o;this._setup();for(var u=-1,a=n*this.trailLength;++u<a&&!this.stopped;){s=e+u;i=t[s]||t[s-n];if(!i)continue;this.alpha=Math.round(1e3*(u/(a-1)))/1e3;this._.globalAlpha=this.alpha;if(this.fillColor){this._.fillStyle=this.fillColor}if(this.strokeColor){this._.strokeStyle=this.strokeColor}o=e/(this.points.length-1);indexD=u/(a-1);this._preStep(i,indexD,o);this.stepMethod(i,indexD,o)}this._teardown();this.imageData[e]=this._.getImageData(0,0,this.fullWidth,this.fullWidth);return true},draw:function(){if(!this.prep(this.frame)){this._.clearRect(0,0,this.fullWidth,this.fullWidth);this._.putImageData(this.imageData[this.frame],0,0)}if(this.converter&&this.converter.step){this.converter.step(this)}if(!this.iterateFrame()){if(this.converter&&this.converter.teardown){this.converter.teardown(this);this.converter=null}}},iterateFrame:function(){this.frame+=this.stepsPerFrame;if(this.frame>=this.points.length){this.frame=0;return false}return true},play:function(){this.stopped=false;var e=this;this.timer=setInterval(function(){e.draw()},1e3/this.fps)},stop:function(){this.stopped=true;this.timer&&clearInterval(this.timer)}};window.Sonic=t})()