if(!("CanvasRenderingContext2D" in this)){CanvasRenderingContext2D={};CanvasRenderingContext2D.prototype=document.createElement("canvas").getContext("2d").__proto__}var C=CanvasRenderingContext2D.prototype;("restore,rotate,save,scale,translate,arc,arcTo,bezierCurveTo,beginPath,clip,closePath,lineTo,moveTo,quadraticCurveTo,rect,stroke,strokeRect,clearRect,fill,fillRect,clip,drawImage,drawImageFromRect").split(",").forEach(function(b){if(b in C){var a=C[b];C[b]=function(){return a.apply(this,arguments)||this}}});CanvasRenderingContext2D.prototype.sharpRect=function(x,y,w,h){with(this){fillRect(x,y,w,1);fillRect(x,y+1,1,h-1);fillRect(x,y+h,w+1,1);fillRect(x+w,y,1,h)}};CanvasRenderingContext2D.prototype.vLine=function(a,c,b){this.fillRect(a,c,1,b)};CanvasRenderingContext2D.prototype.hLine=function(a,c,b){this.fillRect(a,c,b,1)};CanvasRenderingContext2D.prototype.fillPolygon=function(vertices,fs){with(this){beginPath();moveTo(vertices[0],vertices[1]);for(var i=2;i<vertices.length;i+=2){lineTo(vertices[i],vertices[i+1])}closePath();fillStyle=fs;fill()}};CanvasRenderingContext2D.prototype.renderBox=function(color,point){var origin=new Point(point.x*this.tetris.gridsize.width,point.y*this.tetris.gridsize.height);this.translate(origin.x,origin.y);if(color==0){this.clearRect(0,0,this.tetris.box.width,this.tetris.box.height)}else{with(this){fillStyle=color.toString();fillRect(0,0,tetris.box.width,tetris.box.height);fillPolygon(tetris.highlightPath,tetris.highlight);fillPolygon(tetris.shadowPath,tetris.shadow)}}this.translate(-origin.x,-origin.y);return color};var __7segment={masks:[1008,384,872,968,408,728,760,1920,1016,984,4,11],paths:[],aspect:2,squeeze:0.5,width:0.08,color:{off:"rgba(94, 220, 50, .7)",on:"rgba(94, 220, 50, .9)"},recalcPaths:function(g){__7segment.squeeze=g;__7segment.paths=[];g=g/(1+g);var f=__7segment.width;var e=f*__7segment.aspect;var d=f/2,c=e/2;var i=d/3,h=c/3;__7segment.paths.push([h,0,1-h,0,1-e-h,f,e+h,f]);__7segment.paths.push([1,i,1,0.5-i,1-e,0.5-d-i,1-e,f+i]);__7segment.paths.push([1,0.5+i,1,1-i,1-e,1-f-i,1-e,0.5+d+i]);__7segment.paths.push([1-h,1,h,1,e+h,1-f,1-e-h,1-f]);__7segment.paths.push([0,1-i,0,0.5+i,e,0.5+d+i,e,1-f-i]);__7segment.paths.push([0,0.5-i,0,i,e,f+i,e,0.5-d-i]);__7segment.paths.push([h,0.5,e+h,0.5-d,1-e-h,0.5-d,1-h,0.5,1-e-h,0.5+d,e+h,0.5+d]);__7segment.paths.push([1-e-2*h,1-f-2*i,1-e-d-h,1-f-i,1-3*e,1-2*f,1-3*e,1-3*f,1-2*e,1-3*f,1-e-2*h,1-3*d-2*i]);__7segment.paths.push([0.5,0.25,0.5+c,0.25+d,0.5+c,0.5-d-2*i,0.5-c,0.5-d-2*i,0.5-c,0.25+d]);__7segment.paths.push([0.5,0.75,0.5+c,0.75-d,0.5+c,0.5+d+2*i,0.5-c,0.5+d+2*i,0.5-c,0.75-d]);__7segment.paths.forEach(function(a){a.forEach(function(b,l,k){if((l%2)){return}k[l]=k[l]*(1-g)+g*(1-k[l+1])})})}};__7segment.recalcPaths(0.2);CanvasRenderingContext2D.prototype.renderDigit=function(b){if(b=="."){b=10}else{if(b=="+"){b=11}}var a=this;b=__7segment.masks[b||0];__7segment.paths.forEach(function(d,c){if(1<<9-c&b){a.fillPolygon(d,__7segment.color.on)}else{a.fillPolygon(d,__7segment.color.off)}})};CanvasRenderingContext2D.prototype.clearDigit=function(){var a=__7segment.squeeze/3;this.clearRect(-0.02,-0.02,1.04,1.04);return;this.clearRect(a*2,0,1-a*2,1/3);this.clearRect(a,1/3,1-a*2,1/3);this.clearRect(0,2/3,1-a*2,1/3)};CanvasRenderingContext2D.prototype.renderScore=function(g,a,i,b,e){this.save();this.translate(a,i);var d=b*__7segment.aspect;var f=b*(__7segment.squeeze+1),c=this;this.scale(f,d);g.toString().split("").forEach(function(j,h){if(!(e&&e[h]==j)){c.clearDigit();c.renderDigit(j)}c.translate(1.3-__7segment.squeeze,0)});this.restore()};function Viewport(c,a,b){this.pos=c;this.size=a;this.pad=b;this.canvas=null}Viewport.prototype.__defineGetter__("ambientSize",function(){return Rectangle.sum(this.size,this.pad)});Viewport.prototype.__defineGetter__("contentPos",function(){return new Point(this.pos.x+this.pad.width,this.pos.y+this.pad.height)});Viewport.prototype.__defineGetter__("colors",function(){if(!this["private:colors"]){this["private:colors"]=["rgba(240, 104, 251, 0.3)","rgba(247, 240,  53, 0.3)","rgba(144, 248, 122, 0.3)","rgba(252, 131, 117, 0.3)","rgba(112, 240, 234, 0.3)"];this["private:colors"].shuffle()}return this["private:colors"]});Viewport.prototype.shift=function(a){this.canvas.translate(this.pos.x+this.pad.width,this.pos.y+this.pad.height+(a||0))};Viewport.prototype.unshift=function(a){this.canvas.translate(-this.pos.x-this.pad.width,-this.pos.y-this.pad.height-(a||0))};Viewport.prototype.mkFill=function(b,c){var d=this.canvas.createLinearGradient(b.width/4,0,this.size.width*3/4,b.height),a=this.colors.length-1;this.colors.forEach(function(f,e){if(c){f=Color.parse(f);f.alpha/=c;f=f.toString()}d.addColorStop(e/a,f)});return d};Viewport.prototype.enframe=function(){var as=this.ambientSize;with(this.canvas){save();fillStyle=this.mkFill(as);translate(this.pos.x,this.pos.y);sharpRect(0,0,as.width,as.height);restore()}};Viewport.prototype.mkGrid=function(fieldSize,gridType){var v,h,vv,hh,width=this.size.width/fieldSize.width,height=this.size.height/fieldSize.height;if(gridType=="|"){h=1;v=height}else{if(gridType=="+"){h=Math.floor(width*0.55);v=Math.floor(height*0.3)}}vv=Math.floor(v/2);hh=Math.floor(h/2);this.shift();with(this.canvas){fillStyle=this.mkFill(this.size,3);for(var j=1;j<fieldSize.width;++j){if(gridType=="|"){vLine(j*width-1,-this.pad.height,this.pad.height+vv+1);vLine(j*width-1,fieldSize.height*height-vv,this.pad.height+vv-1)}for(var i=1;i<fieldSize.height;++i){vLine(j*width-1,i*height-vv,v);hLine(j*width-hh-1,i*height-1,h)}}}this.unshift()};
