(window.onload = function() {var mouseX;var mouseY;var x=new Array(320,260,200,140, 80,128,176,224,272,320,320,320);var y=new Array(260,260,260,260,260,224,188,152,116, 80,140,200);var a=new Array(12);var b=new Array(12);for (var i=0; i!=13; i++) b[i]=new Array(2,0,0,0,0,0,0,0,0,0,0,0,0);b[0][0]=1;b[4][0]=0; b[4][2]=1;b[9][0]=0; b[9][1]=1;var c=new Array(Math.PI/2.0,Math.acos(3.0/5.0),Math.acos(4.0/5.0),Math.acos(1.0/Math.sqrt(5.0)),Math.acos(2.0/Math.sqrt(5.0)),Math.acos(1.0/Math.sqrt(10.0)),Math.acos(3.0/Math.sqrt(10.0)),Math.acos(2.0/Math.sqrt(13.0)),Math.acos(3.0/Math.sqrt(13.0)),Math.acos(1.0/Math.sqrt(17.0)),Math.acos(4.0/Math.sqrt(17.0)),Math.acos(1.0/Math.sqrt(26.0)),Math.acos(5.0/Math.sqrt(26.0)));var s=new Array(-1,-1,-1);var t=-1;var wx=0,wy=0; function draw() { var canvas = document.getElementById('cvs'); if ( ! canvas || ! canvas.getContext ) return false; var cvs = document.getElementById('cvs'); var ctx = cvs.getContext('2d'); ctx.beginPath(); ctx.clearRect(0,0,400,400); ctx.closePath(); ctx.lineWidth = 3.5; ctx.lineJoin = 'round'; ctx.beginPath(); ctx.moveTo(x[0]+wx,y[0]+wy); for (var i=1; i!=12; i++) { ctx.lineTo(x[i]+wx,y[i]+wy); } ctx.closePath(); ctx.stroke(); for (var i=0; i!=12; i++) { ctx.beginPath(); ctx.arc(x[i]+wx,y[i]+wy,7,0,2*Math.PI,false); ctx.closePath(); ctx.fill(); } if ( t!=-1 ) { ctx.beginPath(); ctx.arc(x[i]+wx,y[i]+wy,10,0,2*Math.PI,false); ctx.closePath(); ctx.fill(); } function optimize(i) { for (var j=1; j!=13; j+=2) { if ( Math.max(0,b[i][j])==0 ) { b[i][0]+=b[i][j]; b[i][j+1]-=b[i][j]; b[i][j]=0; } } for (var j=2; j!=14; j+=2) { if ( Math.max(0,b[i][j])==0 ) { b[i][0]+=b[i][j]; b[i][j-1]-=b[i][j]; b[i][j]=0; } } for (var j=3; j!=13; j+=2) { var m=Math.min(b[i][j],b[i][j+1]); b[i][0]+=m; b[i][j]-=m; b[i][j+1]-=m; } if ( Math.min(2,b[i][4])==2 ) { b[i][4]-=2; b[i][1]++; } if ( Math.min(2,b[i][6])==2 ) { b[i][6]-=2; b[i][2]++; } var m=Math.min(b[i][1],b[i][2]); b[i][0]+=m; b[i][1]-=m; b[i][2]-=m; b[i][0]%=4; } function angle() { for (var i=0; i!=12; i++) { a[i]=0; for (var j=0; j!=13; j++) { a[i]+=b[i][j]*c[j]; } } } function near() { var l=100,m,n=-1; for (var i=0; i!=12; i++) { m=(mouseX-x[i])*(mouseX-x[i])+(mouseY-y[i])*(mouseY-y[i]); if ( Math.min(l,m)==m ) { l=m; n=i; } } return n; } canvas.onmousedown = mouseDownListner; function mouseDownListner(e) { adjustXY(e); } canvas.onmouseup = mouseUpListner; function mouseUpListner(e) { adjustXY(e); } canvas.onmousemove = mouseMoveListner; function mouseMoveListner(e) { adjustXY(e); t=near(); } function adjustXY(e) { var rect = e.target.getBoundingClientRect(); mouseX = e.clientX - rect.left; mouseY = e.clientY - rect.top; } } draw();})();