1. Cat's Eye Technologies
  2. Gemooy

Commits

catseye  committed 698520d

Embed example sources in demo with yoob.js's embed-sources.

  • Participants
  • Parent commits 5fb51eb
  • Branches default

Comments (0)

Files changed (2)

File demo/gemooy.html

View file
  • Ignore whitespace
 <button id="step">Step</button>
 Speed: <input id="speed" type="range" min="0" max="200" value="0" />
 
+<div>
+  example source:
+  <span id="select_source_container">
+    <select id="select_source">
+      <option>(select one...)</option>
+      <option>grow-indefinitely</option>
+      <option>toggle-column</option>
+      <option>turn-around</option>
+    </select>
+  </span>
+</div>
+
 <div id="canvas_viewport">
   <canvas id="canvas" width="400" height="400">
     Your browser doesn't support displaying an HTML5 canvas.
 @   @   @
 </textarea>
 
+<div id="grow-indefinitely" style="display: none;"
+> @@ %
+@  $
+@   #
+     #
+      @# @
+          @
+          @
+     @   @
+</div>
+
+
+<div id="toggle-column" style="display: none;"
+>%   @@   @@
+#  @  $    @
+       @
+#      #
+#
+       @
+#     # #
+#    #
+    @     @
+    @     @@
+#  @ @    @
+@   @   @
+</div>
+
+
+<div id="turn-around" style="display: none;"
+>%           @
+
+
+ @@      @@
+@       @  @
+@          @
+ @   $    @
+      #
+       #
+        @  # @#  @
+              @   @
+              @   #
+           @ @
+
+            @@             @@
+           @              @  @
+           @                 @
+            @               @
+                 #
+                  @  #@#    @
+                 #     @     @ 
+                #         @  @
+               @           @@
+               @       @
+                @     @
+</div>
+
 </body>
 <script src="../src/yoob/controller.js"></script>
 <script src="../src/yoob/playfield.js"></script>
     'step': 'step',
     'load': 'load',
     'edit': 'edit',
+    'speed': 'speed',
+    'select': 'select_source',
     'source': 'program',
-    'display': 'canvas_viewport',
-    'speed': 'speed'
+    'display': 'canvas_viewport'
   });
   c.click_load();
 </script>

File src/yoob/controller.js

View file
  • Ignore whitespace
     this.speed = undefined;
     this.controls = {};
 
-    var makeOnClick = function(controller, key) {
-        if (controller['click_' + key] !== undefined)
+    this.makeEventHandler = function(control, key) {
+        if (this['click_' + key] !== undefined) {
             key = 'click_' + key;
-        return function(e) { controller[key](); }
+        }
+        var self = this;
+        return function(e) {
+          self[key](control); 
+        };
     };
 
     /*
      */
     this.connect = function(dict) {
         var self = this;
-        var keys = ["start", "stop", "step", "load", "edit"];
+        var keys = ["start", "stop", "step", "load", "edit", "select"];
         for (var i in keys) {
             var key = keys[i];
             var value = dict[key];
                 value = document.getElementById(value);
             }
             if (value !== undefined) {
-                value.onclick = makeOnClick(this, key);
+                if (key === 'select') {
+                    value.onchange = this.makeEventHandler(value, key);
+                } else {
+                    value.onclick = this.makeEventHandler(value, key);
+                }
                 this.controls[key] = value;
             }
         }
         if (this.source) this.source.style.display = "block";
     };
 
+    this.click_select = function(control) {
+        this.stop();
+        var source = document.getElementById(
+          control.options[control.selectedIndex].value
+        );
+        var text = source.innerHTML;
+        text = text.replace(/\&lt;/g, '<');
+        text = text.replace(/\&gt;/g, '>');
+        text = text.replace(/\&amp;/g, '&');
+        if (this.source) this.source.value = text;
+        this.load(text);
+    };
+
     this.start = function() {
         if (this.intervalId !== undefined)
             return;