Commits

Anonymous committed 2f7d021

A smidgen less quick, a hair less dirty.

  • Participants
  • Parent commits 1fe41fa

Comments (0)

Files changed (4)

File README.markdown

+Gemooy
+======
+
+This is the reference distribution of Gemooy.
+
+However, it only contains one implementation of Gemooy at the moment, and
+it isn't even the reference implementation.
+
+And it doesn't even contain documentation, either.
+
+These shortcomings will soon be addressed.  Maybe.  For now, see
+[the Gemooy article on the esowiki](http://esolangs.org/wiki/Gemooy)
+for a description of the language.
+
+The implementation of Gemooy contained herein is in Javascript, and uses
+the HTML5 canvas element to display the playfield.

File html/gemooy.html

   </script>
   <style>
 #canvas { border: 1px solid blue; }
+#info { float: right; }
   </style>
 </head>
 <body>
 
+<p id="info">
+Gemooy on:
+<a href="http://catseye.tc/node/Gemooy.html">catseye.tc</a> |
+<a href="https://github.com/catseye/Gemooy">github</a> |
+<a href="http://esolangs.org/wiki/Gemooy">esolangs wiki</a>
+</p>
+
 <h1>Gemooy
 <button id="load">Load</button>
 <button id="start">Start</button>
 Your browser doesn't support displaying an HTML5 canvas.
 </canvas>
 
-<span>
 <textarea id="program" rows="25" cols="40">
 %   @@   @@
 #  @  $    @

File src/gemooy.js

     var interval_id;
 
     var p = Playfield();
-    var ip_x;
-    var ip_y;
-    var ip_dx;
-    var ip_dy;
-    var dp_x;
-    var dp_y;
+    var ip = Cursor(0, 0, 1, 1);
+    var dp = Cursor(0, 0, 0, 0);
 
     self.draw = function() {
         var ctx = canvas.getContext('2d');
         var width = ctx.measureText("@").width;
 
         ctx.fillStyle = "#ff5080";
-        ctx.fillRect(ip_x * width, ip_y * height, width, height);
+        ctx.fillRect(ip.x * width, ip.y * height, width, height);
 
         ctx.fillStyle = "#50ff80";
-        ctx.fillRect(dp_x * width, dp_y * height, width, height);
+        ctx.fillRect(dp.x * width, dp.y * height, width, height);
 
         ctx.fillStyle = "black";
         p.foreach(function (x, y, value) {
         });
     }
 
-    var rotate_clockwise = function() {
-        if (ip_dx === 0 && ip_dy === -1) {
-            ip_dx = 1; ip_dy = -1;
-        } else if (ip_dx === 1 && ip_dy === -1) {
-            ip_dx = 1; ip_dy = 0;
-        } else if (ip_dx === 1 && ip_dy === 0) {
-            ip_dx = 1; ip_dy = 1;
-        } else if (ip_dx === 1 && ip_dy === 1) {
-            ip_dx = 0; ip_dy = 1;
-        } else if (ip_dx === 0 && ip_dy === 1) {
-            ip_dx = -1; ip_dy = 1;
-        } else if (ip_dx === -1 && ip_dy === 1) {
-            ip_dx = -1; ip_dy = 0;
-        } else if (ip_dx === -1 && ip_dy === 0) {
-            ip_dx = -1; ip_dy = -1;
-        } else if (ip_dx === -1 && ip_dy === -1) {
-            ip_dx = 0; ip_dy = -1;
-        }
-    }
-
-    var rotate_counterclockwise = function() {
-        if (ip_dx === 0 && ip_dy === -1) {
-            ip_dx = -1; ip_dy = -1;
-        } else if (ip_dx === -1 && ip_dy === -1) {
-            ip_dx = -1; ip_dy = 0;
-        } else if (ip_dx === -1 && ip_dy === 0) {
-            ip_dx = -1; ip_dy = 1;
-        } else if (ip_dx === -1 && ip_dy === 1) {
-            ip_dx = 0; ip_dy = 1;
-        } else if (ip_dx === 0 && ip_dy === 1) {
-            ip_dx = 1; ip_dy = 1;
-        } else if (ip_dx === 1 && ip_dy === 1) {
-            ip_dx = 1; ip_dy = 0;
-        } else if (ip_dx === 1 && ip_dy === 0) {
-            ip_dx = 1; ip_dy = -1;
-        } else if (ip_dx === 1 && ip_dy === -1) {
-            ip_dx = 0; ip_dy = -1;
-        }
-    }
-
-    var is_headed = function(dx, dy) {
-        return ip_dx === dx && ip_dy === dy;
-    }
-
-    var advance = function() {
-        ip_x += ip_dx;
-        ip_y += ip_dy;
-    }
-
     var increment = function(x, y) {
         var data = p.get(x, y);
         if (data === undefined) {
     }
 
     self.step = function() {
-        var instr = p.get(ip_x, ip_y);
+        var instr = p.get(ip.x, ip.y);
 
         if (instr === '@') {
-            var data = p.get(dp_x, dp_y);
+            var data = p.get(dp.x, dp.y);
             if (data === undefined) {
-                rotate_clockwise();
+                ip.rotate_clockwise();
             } else if (data == '#') {
-                rotate_counterclockwise();
+                ip.rotate_counterclockwise();
             }
         } else if (instr === '#') {
-            if (is_headed(0, -1)) {
-                dp_y--;
-                advance();
-            } else if (is_headed(0, 1)) {
-                dp_y++;
-                advance();
-            } else if (is_headed(1, 0)) {
-                dp_x++;
-                advance();
-            } else if (is_headed(-1, 0)) {
-                dp_x--;
-                advance();
-            } else if (is_headed(-1, -1) || is_headed(1, -1)) {
-                increment(dp_x, dp_y);
-            } else if (is_headed(-1, 1) || is_headed(1, 1)) {
-                decrement(dp_x, dp_y);
+            if (ip.is_headed(0, -1)) {
+                dp.y--;
+                ip.advance();
+            } else if (ip.is_headed(0, 1)) {
+                dp.y++;
+                ip.advance();
+            } else if (ip.is_headed(1, 0)) {
+                dp.x++;
+                ip.advance();
+            } else if (ip.is_headed(-1, 0)) {
+                dp.x--;
+                ip.advance();
+            } else if (ip.is_headed(-1, -1) || ip.is_headed(1, -1)) {
+                increment(dp.x, dp.y);
+            } else if (ip.is_headed(-1, 1) || ip.is_headed(1, 1)) {
+                decrement(dp.x, dp.y);
             }
         }
 
-        advance();
+        ip.advance();
         self.draw();
     }
 
         p.load(0, 0, textarea.val());
         p.foreach(function (x, y, value) {
             if (value === '$') {
-                ip_x = x;
-                ip_y = y;
+                ip.x = x;
+                ip.y = y;
                 return ' ';
             } else if (value === '%') {
-                dp_x = x;
-                dp_y = y;
+                dp.x = x;
+                dp.y = y;
                 return ' ';
             }
         });
-        ip_dx = 1;
-        ip_dy = 1;
+        ip.dx = 1;
+        ip.dy = 1;
         self.draw();
     }
 

File src/playfield.js

+function Cursor(x, y, dx, dy) {
+    var self = {};
+    self.x = x;
+    self.y = y;
+    self.dx = dx;
+    self.dy = dy;
+
+    self.is_headed = function(dx, dy) {
+        return self.dx === dx && self.dy === dy;
+    }
+
+    self.advance = function() {
+        self.x += self.dx;
+        self.y += self.dy;
+    }
+
+    self.rotate_clockwise = function() {
+        if (self.dx === 0 && self.dy === -1) {
+            self.dx = 1; self.dy = -1;
+        } else if (self.dx === 1 && self.dy === -1) {
+            self.dx = 1; self.dy = 0;
+        } else if (self.dx === 1 && self.dy === 0) {
+            self.dx = 1; self.dy = 1;
+        } else if (self.dx === 1 && self.dy === 1) {
+            self.dx = 0; self.dy = 1;
+        } else if (self.dx === 0 && self.dy === 1) {
+            self.dx = -1; self.dy = 1;
+        } else if (self.dx === -1 && self.dy === 1) {
+            self.dx = -1; self.dy = 0;
+        } else if (self.dx === -1 && self.dy === 0) {
+            self.dx = -1; self.dy = -1;
+        } else if (self.dx === -1 && self.dy === -1) {
+            self.dx = 0; self.dy = -1;
+        }
+    }
+
+    self.rotate_counterclockwise = function() {
+        if (self.dx === 0 && self.dy === -1) {
+            self.dx = -1; self.dy = -1;
+        } else if (self.dx === -1 && self.dy === -1) {
+            self.dx = -1; self.dy = 0;
+        } else if (self.dx === -1 && self.dy === 0) {
+            self.dx = -1; self.dy = 1;
+        } else if (self.dx === -1 && self.dy === 1) {
+            self.dx = 0; self.dy = 1;
+        } else if (self.dx === 0 && self.dy === 1) {
+            self.dx = 1; self.dy = 1;
+        } else if (self.dx === 1 && self.dy === 1) {
+            self.dx = 1; self.dy = 0;
+        } else if (self.dx === 1 && self.dy === 0) {
+            self.dx = 1; self.dy = -1;
+        } else if (self.dx === 1 && self.dy === -1) {
+            self.dx = 0; self.dy = -1;
+        }
+    }
+
+    return self;
+}
+
 function Playfield() {
-    var self = {}
-    var store = {}
+    var self = {};
+    var store = {};
     self.min_x = undefined;
     self.min_y = undefined;
     self.max_x = undefined;