-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqanvas-min.js
1 lines (1 loc) · 4.46 KB
/
qanvas-min.js
1
(function(){root=this;root.qanvas=function(a,b,c,d){var e=document.getElementById(a||"canvas");if(!e)throw Error(a+" not found");var f=e.getContext("2d");if(!f)throw Error(a+".getContext('2d') not found");var g=Math.max(document.body.clientWidth||window.innerWidth||document.body.scrollWidth,window.screen.availWidth||0);var h=window.innerheight||document.body.clientHeight||document.body.scrollHeight||window.screen.availHeight;var i=e.width=b?g*(c||1):e.width*(c||1),j=e.height=b?h*(d||1):e.height*(d||1);var k=Math.PI,l=k/180,m=Math.cos,n=Math.sin;var o=function(){this.width=i;this.height=j};o.prototype={listen:function(a,b){e.addEventListener(a,function(a){b(a.offsetX||a.pageX,a.offsetY||a.pageY)},false)},paper:{width:i,height:j,midWidth:i/2,midHeight:j/2,circle:function(a,b,c){f.beginPath();f.arc(a,b,c,0,k*2,true);f.closePath();f.stroke();f.fill();return this},halfCircle:function(a,b,c,d,e,g){if(d)d=l*d;f.beginPath();if(e&&g){var h=this.helper.convert(a,b,e,g,d);f.arc(h[0],h[1],c,d,d+k,true)}else{f.arc(a,b,c,d||0,(d||0)+k,true)}f.closePath();f.stroke();f.fill();return this},ellipse:function(a,b,c,d,e,g,h){var i=[a+d,b-c],j=[a+d,b+c],k=[a-d,b+c],m=[a-d,b-c],n=[a,b+c],o=[a,b-c];if(e){e=l*e;var g=g||a,h=h||b;i=this.helper.convert(a+d,b-c,g,h,e);j=this.helper.convert(a+d,b+c,g,h,e);k=this.helper.convert(a-d,b+c,g,h,e);m=this.helper.convert(a-d,b-c,g,h,e);n=this.helper.convert(a,b+c,g,h,e);o=this.helper.convert(a,b-c,g,h,e)}var p=i.concat(j.concat(n)),q=k.concat(m.concat(o));f.beginPath();f.moveTo.apply(f,o);f.bezierCurveTo.apply(f,p);f.bezierCurveTo.apply(f,q);f.closePath();f.stroke();f.fill();return this},halfEllipse:function(a,b,c,d,e,g,h){var i=[a+d,b-c],j=[a+d,b+c],k=[a,b+c],m=[a,b-c];if(e){e=l*e;var g=g||a,h=h||b;i=this.helper.convert(a+d,b-c,g,h,e);j=this.helper.convert(a+d,b+c,g,h,e);k=this.helper.convert(a,b+c,g,h,e);m=this.helper.convert(a,b-c,g,h,e)}var n=i.concat(j.concat(k));f.beginPath();f.moveTo.apply(f,m);f.bezierCurveTo.apply(f,n);f.closePath();f.stroke();f.fill();return this},square:function(a,b,c,d,e,g){var h=[a,b];xwy=[a+c,b],xwyh=[a+c,b+c],xyh=[a,b+c];if(d){d=l*d;var e=e||a+c/2,g=g||b+c/2;h=this.helper.convert(a,b,e,g,d);xwy=this.helper.convert(a+c,b,e,g,d);xwyh=this.helper.convert(a+c,b+c,e,g,d);xyh=this.helper.convert(a,b+c,e,g,d)}f.beginPath();f.moveTo.apply(f,h);f.lineTo.apply(f,xwy);f.lineTo.apply(f,xwyh);f.lineTo.apply(f,xyh);f.closePath();f.stroke();f.fill();return this},rect:function(a,b,c,d,e,g,h){var i=[a,b],j=[a+c,b],k=[a+c,b+d],m=[a,b+d];if(e){e=l*e;var g=g||a+c/2,h=h||b+d/2;i=this.helper.convert(a,b,g,h,e);j=this.helper.convert(a+c,b,g,h,e);k=this.helper.convert(a+c,b+d,g,h,e);m=this.helper.convert(a,b+d,g,h,e)}f.beginPath();f.moveTo.apply(f,i);f.lineTo.apply(f,j);f.lineTo.apply(f,k);f.lineTo.apply(f,m);f.closePath();f.stroke();f.fill();return this},quadri:function(a,b,c,d,e,g,h,i,j,k,m){var n=[a,b];xwy=[c,d],xwyh=[e,g],xyh=[h,i];if(j){j=l*j;var k=k||(a+c+e+h)/4,m=m||(b+d+g+i)/4;n=this.helper.convert(a,b,k,m,j);xwy=this.helper.convert(c,d,k,m,j);xwyh=this.helper.convert(e,g,k,m,j);xyh=this.helper.convert(h,i,k,m,j)}f.beginPath();f.moveTo.apply(f,n);f.lineTo.apply(f,xwy);f.lineTo.apply(f,xwyh);f.lineTo.apply(f,xyh);f.closePath();f.stroke();f.fill();return this},text:function(a,b,c){f.fillText(c,a,b);return this},image:function(a,b,c){var d=new Image;d.src=c;d.onload=function(){f.drawImage(this,a,b)}},line:function(a,b,c,d,e,g,h){var i=[a,b],j=[c,d];if(e){e=l*Math.PI;var g=g||(a+c)/2,h=h||(b+d)/2;i=this.helper.convert(a,b,g,h,e);j=this.helper.convert(c,d,g,h,e)}f.beginPath();f.moveTo.apply(f,i);f.lineTo.apply(f,j);f.closePath();f.stroke();f.fill();return this},helper:{c2p:function(a,b){var c=Math.sqrt(a*a+b*b),d=Math.atan(b/a);if(a<0&&b>=0)d+=k;if(a<0&&b<0)d+=k;if(a>=0&&b<0)d+=2*k;return[c,d]},p2c:function(a,b){var c=a*m(b),d=a*n(b);return[c,d]},convert:function(a,b,c,d,e){var f=this.c2p(a-c,b-d);f[1]+=e;f=this.p2c.apply(null,f);f[0]+=c;f[1]+=d;return f}},fill:function(a){if(!a)throw Error("missing arguments");f.fillStyle=a;return this},stroke:function(a){if(!a)throw Error("missing arguments");f.strokeStyle=a;return this},style:function(a){if(a&&typeof a!=="object")throw TypeError("style should be an object, but it's a "+typeof a);for(var b in a){if(f.hasOwnProperty(b)||typeof f[b]!=="function"){f[b]=a[b]}}return this},fastStyle:function(a,b){if(!a||!b)throw Error("missing arguments");f[a]=b;return this},clear:function(a,b,c,d){arguments.length===4?f.clearRect(a,b,c,d):f.clearRect(0,0,this.width,this.height);return this}}};return new o};return root}).call(this)