git @ Cat's Eye Technologies yoob.js / master eg / tape.html
master

Tree @master (Download .tar.gz)

tape.html @masterraw · history · blame

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <title>yoob.Tape Demo</title>
  <script src="../src/yoob/tape.js"></script>
  <script src="../src/yoob/cursor.js"></script>
  <script src="../src/yoob/tape-canvas-view.js"></script>
  <script src="../src/yoob/tape-html-view.js"></script>
  <style>
#canvas_view { border: 1px solid blue; }
#html_view { border: 1px solid red; font-size: 20px; }
  </style>
</head>
<body>

<h1>yoob.Tape Demo</h1>

<canvas id="canvas_view" width="400" height="40">
Your browser doesn't support displaying an HTML5 canvas.
</canvas>

<pre id="html_view"></pre>

<button id="write_0">Write 0</button>
<button id="write_1">Write 1</button>
<button id="read">Read</button>
<button id="left">Move Left</button>
<button id="right">Move Right</button>

</body>
<script>
  var head = new yoob.Cursor().init();
  var tape = new yoob.Tape().init({ cursors: [head] });

  var canvasView = new yoob.TapeCanvasView().init({
      tape: tape,
      canvas: document.getElementById('canvas_view'),
      cellWidth: 20,
      cellHeight: 20
  });

  var htmlView = new yoob.TapeHTMLView().init({
      tape: tape,
      element: document.getElementById('html_view')
  });

  document.getElementById('write_0').onclick = function(e) {
    tape.write("0");
    canvasView.draw();
    htmlView.draw();
  };

  document.getElementById('write_1').onclick = function(e) {
    tape.write("1");
    canvasView.draw();
    htmlView.draw();
  };

  document.getElementById('read').onclick = function(e) {
    alert(tape.read());
  };

  document.getElementById('left').onclick = function(e) {
    head.moveLeft();
    canvasView.draw();
    htmlView.draw();
  };

  document.getElementById('right').onclick = function(e) {
    head.moveRight();
    canvasView.draw();
    htmlView.draw();
  };

</script>