return {r: r, q: q};
}
*/
+
+
+
+DRAWHEX_RAD_SCALE = 1.18;
+
+function drawHexagon(ctx,x,y,sz,color) {
+ ctx.save();
+ ctx.strokeStyle=color;
+ ctx.fillStyle=color;
+ ctx.beginPath();
+ let r = sz * Math.sqrt(3)/2 * DRAWHEX_RAD_SCALE;
+ for(let i=0; i<=6;i++) {
+ let ang = Math.PI/6 + i*Math.PI/3;
+ let ix = x + r * Math.cos(ang);
+ let iy = y + r * Math.sin(ang);
+ ctx.lineTo(ix,iy);
+ }
+ ctx.fill();
+ ctx.restore();
+}
<script src="cell.js"></script>
<script src="play.js"></script>
<script src="rps.js"></script>
- <script src="draw.js"></script>
<script>
function run() {
lc();
return new WWHex(o.state, o.q, o.r);
}
drawState(ctx, x, y, sz) {
- ctx.save();
+ switch(this.state) {
+ case WWState.OFF:
+ drawHexagon(ctx,x,y,sz,'rgb(0,0,0)');
+ return;
+ break;
+ case WWState.TAIL:
+ drawHexagon(ctx,x,y,sz,'rgb(0,0,255)');
+ return;
+ break;
+ case WWState.HEAD:
+ drawHexagon(ctx,x,y,sz,'rgb(255,0,0)');
+ return;
+ break;
+ case WWState.EMPTY:
+ return;
+ break;
+ }
+ /*ctx.save();
switch(this.state) {
case WWState.OFF:
ctx.fillStyle = 'rgb(0,0,0)';
ctx.arc(x,y,r,0,Math.PI*2,true);
ctx.fill();
ctx.stroke();
- ctx.restore();
+ ctx.restore();*/
}
};