]> git.eli173.com Git - hexgrid/commitdiff
new drawing which is great
authorElijah Cohen <eli@eli173.com>
Sun, 10 Jul 2022 06:51:54 +0000 (01:51 -0500)
committerElijah Cohen <eli@eli173.com>
Sun, 10 Jul 2022 06:51:54 +0000 (01:51 -0500)
cell.js
rps.html
wireworld.js

diff --git a/cell.js b/cell.js
index 22431e2126952087c6f5fab083d6317ba62d2bd5..261b4b94dfc4167e7b8360f44646bf6cc171a265 100644 (file)
--- a/cell.js
+++ b/cell.js
@@ -117,3 +117,23 @@ function getClickCoords(c, scale, xoff, yoff, event) {
                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();
+}
index d558937d242c2872fca0dd8f415aa0a737837394..3fe7a40467f051e41029554c175e578fbc587f70 100644 (file)
--- a/rps.html
+++ b/rps.html
@@ -6,7 +6,6 @@
                <script src="cell.js"></script>
                <script src="play.js"></script>
                <script src="rps.js"></script>
-               <script src="draw.js"></script>
                <script>
                        function run() {
                                        lc();
index 944452a6298d4c369674c86ef246cda1d8892f01..98147610ceb9781c12944dd7c6cb1a292877f2a2 100644 (file)
@@ -33,7 +33,24 @@ class WWHex extends Hex {
                                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)';
@@ -56,7 +73,7 @@ class WWHex extends Hex {
                                ctx.arc(x,y,r,0,Math.PI*2,true);
                                ctx.fill();
                                ctx.stroke();
-                               ctx.restore();
+                               ctx.restore();*/
                }
 };