From cd99f67af2803ec37e5191673f7ee609b432f8ce Mon Sep 17 00:00:00 2001 From: mumuy Date: Fri, 24 Mar 2017 16:01:51 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E5=9C=B0=E5=9B=BE=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 115 +++++++++++++++++++++---------------------------------- 1 file changed, 44 insertions(+), 71 deletions(-) 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(); + } + }); } } }