-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot.min.js
1 lines (1 loc) · 3.6 KB
/
dot.min.js
1
/* dot.js - v2.1.2 */Dot=function(){function e(e){var t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;e=e.replace(t,function(e,t,n,r){return t+t+n+n+r+r});var n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}function t(e){var t=e.toString(16);return t.length==1?"0"+t:t}function n(e,n,r){return"#"+t(e)+t(n)+t(r)}return function(t){this.setCA=function(e){return this._ca=e,this.setCX(e.getContext("2d")),this},this.setCX=function(e){return this._cx=e,this._pixel=e.createImageData(1,1),this.setColor("#000"),this},this.setColor=function(t){return c=e(t),this._pixel.data[0]=c.r,this._pixel.data[1]=c.g,this._pixel.data[2]=c.b,this._pixel.data[3]=255,this},this.getColor=function(){var e=this._pixel.data;return n(e[0],e[1],e[2])},this.height=function(){return this._ca.height},this.width=function(){return this._ca.width},this.size=function(){return{h:this.height(),w:this.width()}},this.setX=function(e){return this._x=Math.round(e),this},this.coords2=function(e,t){var n=this._ca.width/(2*this._x),r=this._ca.height/(2*this._x);return{x:e*n+n,y:-t*r+r}},this.clear=function(){return this._cx.clearRect(0,0,this._ca.width,this._ca.height),this},this.putPX=function(e,t){return this._cx.putImageData(this._pixel,t,e),this},this.dot=function(e,t){if(this._x==1)return this.putPX(e,t);for(var n=0;n<this._x;n++)for(var r=0;r<this._x;r++)this.putPX(e*this._x+n,t*this._x+r);return this},this.dot2=function(e,t){var n=this.coords2(e,t);return this.dot(n.y,n.x),this},this.line=function(e,t,n,r){e=Math.round(e),t=Math.round(t),n=Math.round(n),r=Math.round(r);var i=Math.abs(n-e),s=Math.abs(r-t),o=e<n?1:-1,u=t<r?1:-1,a=i-s;for(;;){this.dot(t,e);if(e==n&&t==r)break;var f=2*a;f>-s&&(a-=s,e+=o),f<i&&(a+=i,t+=u)}return this},this.line2=function(e,t,n,r){var i=this.coords2(e,t),s=this.coords2(n,r);return this.line(i.x,i.y,s.x,s.y),this},this.rect=function(e,t,n,r){return this.line(e,t,e,r),this.line(e,r,n,r),this.line(n,r,n,t),this.line(n,t,e,t),this},this.rect2=function(e,t,n,r){return this.line2(e,t,e,r),this.line2(e,r,n,r),this.line2(n,r,n,t),this.line2(n,t,e,t),this},this.rectf=function(e,t,n,r){return this._x!=1&&(e*=this._x,t*=this._x,n*=this._x,r*=this._x),this._cx.beginPath(),this._cx.rect(e,t,n-e+this._x,r-t+this._x),this._cx.fillStyle=this.getColor(),this._cx.fill(),this},this.rectf2=function(e,t,n,r){var i=this.coords2(e,t),s=this.coords2(n,r);return this.rectf(i.x,i.y,s.x,s.y),this},this.circle=function(e,t,n){var r=0,i=n,s=3-2*n;if(!n)return;while(i>=r)this.dot(t-i,e-r),this.dot(t-r,e-i),this.dot(t-r,e+i),this.dot(t-i,e+r),this.dot(t+i,e-r),this.dot(t+r,e-i),this.dot(t+r,e+i),this.dot(t+i,e+r),s<0?s+=4*r++ +6:s+=4*(r++ -i--)+10;return this},this.circle2=function(e,t,n){var r=this.coords2(e,t),i=this.coords2(n-1,0);return this.circle(r.x,r.y,i.x),this},this.param=function(e,t,n,r){var i=n==undefined?0:t,s=n==undefined?t:n,o=r==undefined?1:r;for(var u=i;u<=s;u+=o){var a=e(u);this.dot(a.y,a.x)}return this},this.param2=function(e,t,n,r){var i=n==undefined?0:t,s=n==undefined?t:n,o=r==undefined?1:r;for(var u=i;u<=s;u+=o){var a=e(u),f=this.coords2(a.x,a.y);console.log(f.y,f.x),this.dot(f.y,f.x)}return this},this.parl=function(e,t,n,r){var i=n==undefined?0:t,s=n==undefined?t:n,o=r==undefined?1:r,u=e(i);for(var a=i+o;a<=s;a+=o){var f=e(a);this.line(u.x,u.y,f.x,f.y),u.x=f.x,u.y=f.y}return this},this.parl2=function(e,t,n,r){var i=n==undefined?0:t,s=n==undefined?t:n,o=r==undefined?1:r,u=e(i),a=this.coords2(u.x,u.y);for(var f=i+o;f<=s;f+=o){var l=e(f),c=this.coords2(l.x,l.y);this.line(a.x,a.y,c.x,c.y),a.x=c.x,a.y=c.y}return this},this._x=1,t&&this.setCA(document.getElementById(t))}}();