/* by Remy Sharp */
 (function(){function o(b,e,d){if(d==undefined)d={};this.x=b;this.y=e;this.base=d.base||20;this.incAmount=d.incAmount||0.25;this.growSpeed=d.growSpeed||10;this.growDelay=d.growDelay||1E3;this.drawLength=this.length=0;this.vectors=[]}function h(b){return~~(Math.random()*b)}function r(){var b=h(3)+3,e=s!=2?50:250;setTimeout(function(){if(b--&&k){z();setTimeout(arguments.callee,h(e)+e)}},h(e)+e);k=setTimeout(r,h(s!=2?1E3:2E3))}function A(){var b=m.length;clearTimeout(k);for(k=null;b--;)m[b].stop()}function p(b){b--;
 f.save();f.fillStyle=b<3?"#000":"#fff";f.fillRect((f.canvas.width-460)/2-2,(f.canvas.height-169)/2-2,464,173);f.drawImage(t,0,169*b,460,169,(f.canvas.width-460)/2,(f.canvas.height-169)/2,460,169);f.restore()}function w(){for(var b=f.getImageData(0,0,i.width,5),e=b.data.length,d=0,a=f.fillStyle=="#ffffff"?255:0,g=0;g<e;g+=4)b.data[g]===a&&d++;if(d>=b.data.length/4*0.6){A();clearInterval(u);setTimeout(function(){var c;if(q==false){f.fillStyle=f.strokeStyle="#000000";document.body.className="white";
 c=4;setTimeout(function(){if(c<=6){p(c++);setTimeout(arguments.callee,h(250)+250)}},h(250)+250)}else{document.body.className="black";f.fillStyle=f.strokeStyle="#ffffff";c=1;setTimeout(function(){if(c<=3){p(c++);setTimeout(arguments.callee,h(250)+250)}},h(250)+250)}p(c++);q=!q;k=setTimeout(r,3E3);u=setInterval(w,1E3)},100)}}function x(){clearTimeout(y);y=setTimeout(function(){var b=i.width,e=i.height,d=f.getImageData(0,0,b,e);f.save();i.width=window.innerWidth;i.height=window.innerHeight;f.save();
 f.fillStyle=q?"#fff":"#000";f.fillRect(0,0,i.width,i.height);f.restore();f.putImageData(d,(i.width-b)/2,(i.height-e)/2)},200)}var n=function(){function b(a,g){this.x=a;this.y=g;this.magnatude=this.mag()}var e=180/Math.PI,d=Math.PI/180;b.prototype={toString:function(a){a=a||3;return"["+this.x.toFixed(a)+", "+this.y.toFixed(a)+":"+this.mag().toFixed(a)+"]"},set:function(a,g){this.x=a;this.y=g},clone:function(){return new b(this.x,this.y)},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},
 magSquared:function(){return this.x*this.x+this.y*this.y},add:function(a){this.x+=a.x;this.y+=a.y},sub:function(a){this.x-=a.x;this.y-=a.y},mult:function(a){this.x*=a;this.y*=a;return this},div:function(a){this.x/=a;this.y/=a},dist:function(){},dot:function(a){return this.x*a.x+this.y*a.y},copy:function(a){this.x=a.x;this.y=a.y},angle:function(a){return a?Math.atan2(this.y,this.x)*e:Math.atan2(this.y,this.x)},rotate:function(a){var g=Math.cos(a*d);a=Math.sin(a*d);var c=new b;c.copy(this);this.x=c.x*
 g-c.y*a;this.y=c.x*a+c.y*g},rotateAroundPoint:function(a,g){var c=new b;c.copy(this);c.sub(a);c.rotate(g);c.add(a);this.copy(c)},normalise:function(){var a=this.mag();this.x/=a;this.y/=a;return this}};return b}();o.prototype={add:function(b,e){var d,a=this,g=0;d=b instanceof n?b:new n(b,e);this.vectors.push(d);this.length+=d.magnatude;this.inc=1/this.length;this.vectors.forEach(function(c,j){c.id=j+1;c.segLength=c.magnatude*a.inc;c.base=a.base*(1-g);g+=c.segLength;c.top=a.base*(1-g);c.aggLength=g})},
 grow:function(b){var e=this.drawLength,d=this;this.drawLength+=b;var a=this.drawLength/(this.growSpeed/20);this.interval=setInterval(function(){e+=a;d.draw(e);if(e>=d.drawLength||e>=1){clearInterval(d.interval);if(e<1)d.timeout=setTimeout(function(){d.grow(d.incAmount)},d.growDelay)}},20)},growByJoin:function(b){var e=0,d=this,a;b||(b=0);a=this.vectors[b].aggLength-0.01;var g=a/(this.growSpeed/20);this.interval=setInterval(function(){e+=g;d.draw(e);if(e>=a||e>=1){clearInterval(d.interval);if(e<0.95)d.timeout=
 setTimeout(function(){d.growByJoin(b+1)},d.growDelay)}},20)},stop:function(){clearInterval(this.interval);clearTimeout(this.timeout)},draw:function(b){var e=this.x,d=this.y,a=this.vectors[0],g=0,c=0,j;f.beginPath();for(f.moveTo(this.x-this.base*b/2,this.y);c<this.vectors.length;c++){v=this.vectors[c];if(v.aggLength<=b){e+=v.x;d+=v.y;j=this.base*(b-v.aggLength)/2;if(c<this.vectors.length-1){a=v.clone();var l=this.vectors[c+1].clone();a.add(l);a.rotate(90);a.normalise();a.mult(j);f.lineTo(e-a.x,d-a.y)}else f.lineTo(e-
 j,d);g+=v.segLength}else{if(g-b!=0){a=v.clone();a.mult((b-g)/v.segLength);e+=a.x;d+=a.y;f.lineTo(e,d);e-=a.x;d-=a.y;c>0&&a.add(this.vectors[c-1]);a.rotate(-90);a.normalise();f.lineTo(e-a.x,d-a.y)}break}}for(c--;c>0;c--){v=this.vectors[c];e-=v.x;d-=v.y;j=this.base*(b-this.vectors[c-1].aggLength)/2;if(c>0){a=v.clone();a.add(this.vectors[c-1]);a.rotate(90);a.normalise();a.mult(j);f.lineTo(e+a.x,d+a.y)}else f.lineTo(e+j,d)}f.lineTo(this.x+this.base*b/2,this.y);f.closePath();f.fill()}};var i=document.querySelector("canvas"),
 f=i.getContext("2d"),m=[],t=document.createElement("img"),q=true,k,u,y,s=h(3),B="createTouch"in document?"touchstart":"click";i.width=window.innerWidth;i.height=window.innerHeight;t.src="radiohead-sprite.gif";var z=[function(){var b=new o(h(window.innerWidth),window.innerHeight,{growDelay:6E3+Math.random()*9E3,growSpeed:100,base:100+h(50)}),e=Math.random()<0.5?-1:1,d=window.innerHeight,a=h(5)+8,g=0;a=window.innerHeight/a;var c=window.innerHeight*0.5,j,l;for(m.push(b);g<d;){l=new n(0,-(h(c)+a));j=
 h(60);l.rotate(e*j);g-=l.y;b.add(l);e*=-1}b.growByJoin()},function(){var b=new o(h(window.innerWidth),window.innerHeight,{growDelay:6E3+Math.random()*9E3,growSpeed:100,base:50+h(50)}),e=Math.random()<0.5?-1:1,d=window.innerHeight,a=0,g,c;for(m.push(b);a<d;){c=new n(0,-(Math.random()*d/2));g=h(85);c.rotate(e*g);a-=c.y;b.add(c);e*=-1}b.growByJoin()},function(){var b=new o(h(window.innerWidth),window.innerHeight,{growDelay:6E3+Math.random()*12E3,growSpeed:1E3+h(1E3),base:50+h(50)}),e=Math.random()<0.5?
 -1:1,d=window.innerHeight,a=0,g,c;for(m.push(b);a<d;){c=new n(0,-(Math.random()*d/2));g=h(85);c.rotate(e*g);a-=c.y;b.add(c);e*=-1}b.growByJoin()}][s];t.onload=function(){f.fillStyle="#fff";f.fillRect(0,0,i.width,i.height);p(6);f.fillStyle="#000";k=setTimeout(r,3E3);u=setInterval(w,1E3)};window.addEventListener("resize",x);window.addEventListener("orientationchange",x);document.body.addEventListener(B,function(b){b=b.pageX||b.touches[0].pageX;b>window.innerWidth-44&&b<44&&window.open(i.toDataURL("image/png"))},
 false)})();
