|
(function(){"use strict";if(!HTMLCanvasElement)return;var f=CanvasRenderingContext2D.prototype,PI_PER_180=Math.PI/180;f.clearAll=function(){var c=this;c.save();cc.setTransform(1,0,0,1,0,0);c.clearRect(0,0,c.canvas.width,c.canvas.height);c.restore()};f.rotateContext=function(a,b,d){var c=this;c.translate(b,d);c.rotate(a*PI_PER_180);c.translate(-b,-d)};f.clipWithFunction=function(a){var c=this;c.save();c.globalCompositeOperation="destination-out";a();c.restore()};f.getPolygonPoints=function(x,y,a,b,c){var d,points=[],i=0,Z=360/b;c=(c?c:0)-90;for(;i<b;++i){d=(Z*i+c)*PI_PER_180;points[i]=[Math.cos(d)*a+x,Math.sin(d)*a+y]}return points};f.polygon=function(x,y,a,b,d){var c=this,points=c.getPolygonPoints(x,y,a,b,d),pl=points.length,i=0,ps;c.moveTo(points[0].x,points[0].y);for(;i<pl;++i){ps=points[i];c.lineTo(ps[0],ps[1])}};f.fillPolygon=function(x,y,a,b,d){var c=this;c.beginPath();c.polygon(x,y,a,b,d);c.closePath();c.fill()};f.strokePolygon=function(x,y,a,b,d){var c=this;c.beginPath();c.polygon(x,y,a,b,d);c.closePath();c.stroke()};f.drawPolygon=function(x,y,a,b,d){var c=this;c.beginPath();c.polygon(x,y,a,b,d);c.closePath();c.fill();c.stroke()};f.ellipse=function(L,T,R,B){var c=this,halfW=(R-L)/2,halfH=(B-T)/2,C=L+halfW,M=T+halfH,cw=4*(Math.sqrt(2)-1)*halfW/3,ch=4*(Math.sqrt(2)-1)*halfH/3,p1=C+cw,p2=C-cw,p3=M-ch,p4=M+ch;c.moveTo(C,T);c.bezierCurveTo(p1,T,R,p3,R,M);c.bezierCurveTo(R,p4,p1,B,C,B);c.bezierCurveTo(p2,B,L,p4,L,M);c.bezierCurveTo(L,p3,p2,T,C,T)};f.strokeEllipse=function(L,T,R,B){var c=this;c.beginPath();c.ellipse(L,T,R,B);c.closePath();c.stroke()};f.fillEllipse=function(L,T,R,B){var c=this;c.beginPath();c.ellipse(L,T,R,B);c.closePath();c.fill()};f.drawEllipse=function(L,T,R,B){var c=this;c.beginPath();c.ellipse(L,T,R,B);c.closePath();c.fill();c.stroke()};f.drawRect=function(a,b,d,e){var c=this;c.fillRect(a,b,d,e);c.strokeRect(a,b,d,e)};f.strokeArc=function(x,y,a,b,d,e){var c=this;c.beginPath();c.arc(x,y,a,b,d,e);c.closePath();c.stroke()};f.fillArc=function(x,y,a,b,d,e){var c=this;c.beginPath();c.arc(x,y,a,b,d,e);c.closePath();c.fill()};f.drawArc=function(x,y,a,b,d,e){var c=this;c.beginPath();c.arc(x,y,a,b,d,e);c.closePath();c.fill();c.stroke()};f.arcByDeg=function(x,y,a,b,c,d){arc(x,y,a,b*PI_PER_180,c*PI_PER_180,d)};f.strokeArcByDeg=function(x,y,a,b,d,e){var c=this;c.beginPath();c.arcByDeg(x,y,a,b,d,e);c.closePath();c.stroke()};f.fillArcByDeg=function(x,y,a,b,d,e){var c=this;c.beginPath();c.arcByDeg(x,y,a,b,d,e);c.closePath();c.fill()}})(); |