diff --git a/index.js b/index.js index ccc754d..aec2f86 100644 --- a/index.js +++ b/index.js @@ -153,90 +153,63 @@ data:_DATA, cache:true, draw:function(context){ + context.lineWidth = 2; for(var j=0; j-1){ context.strokeStyle=value==2?"#FFF":"#09C"; var pos = this.coord2position(i,j); - switch(code){ - case 1100: - context.beginPath(); - context.arc(pos.x+this.size/2,pos.y-this.size/2,this.size/2,.5*Math.PI,1*Math.PI,false); - context.stroke(); - context.closePath(); - break; - case 110: - context.beginPath(); - context.arc(pos.x+this.size/2,pos.y+this.size/2,this.size/2,Math.PI,1.5*Math.PI,false); - context.stroke(); - context.closePath(); - break; - case 11: - context.beginPath(); - context.arc(pos.x-this.size/2,pos.y+this.size/2,this.size/2,1.5*Math.PI,2*Math.PI,false); - context.stroke(); - context.closePath(); - break; - case 1001: - context.beginPath(); - context.arc(pos.x-this.size/2,pos.y-this.size/2,this.size/2,0,.5*Math.PI,false); - context.stroke(); - context.closePath(); - break; + switch(code.join('')){ + case '1100': + context.beginPath(); + context.arc(pos.x+this.size/2,pos.y+this.size/2,this.size/2,Math.PI,1.5*Math.PI,false); + context.stroke(); + context.closePath(); + break; + case '0110': + context.beginPath(); + context.arc(pos.x-this.size/2,pos.y+this.size/2,this.size/2,1.5*Math.PI,2*Math.PI,false); + context.stroke(); + context.closePath(); + break; + case '0011': + context.beginPath(); + context.arc(pos.x-this.size/2,pos.y-this.size/2,this.size/2,0,.5*Math.PI,false); + context.stroke(); + context.closePath(); + break; + case '1001': + context.beginPath(); + context.arc(pos.x+this.size/2,pos.y-this.size/2,this.size/2,.5*Math.PI,1*Math.PI,false); + context.stroke(); + context.closePath(); + break; default: - var arr = String.prototype.split.call(code,''); - if(+arr.pop()){ - context.beginPath(); - context.moveTo(pos.x,pos.y); - context.lineTo(pos.x-this.size/2,pos.y); - context.stroke(); - context.closePath(); - } - if(+arr.pop()){ - context.beginPath(); - context.moveTo(pos.x,pos.y); - context.lineTo(pos.x,pos.y+this.size/2); - context.stroke(); - context.closePath(); - } - if(+arr.pop()){ - context.beginPath(); - context.moveTo(pos.x,pos.y); - context.lineTo(pos.x+this.size/2,pos.y); - context.stroke(); - context.closePath(); - } - if(+arr.pop()){ - context.beginPath(); - context.moveTo(pos.x,pos.y); - context.lineTo(pos.x,pos.y-this.size/2); - context.stroke(); - context.closePath(); - } + var dist = this.size/2; + code.forEach(function(v,index){ + if(v){ + context.beginPath(); + context.moveTo(pos.x,pos.y); + context.lineTo(pos.x-_COS[index]*dist,pos.y-_SIN[index]*dist); + context.stroke(); + context.closePath(); + } + }); } } }