3 | 3 |
<title>yoob.Tape Demo</title>
|
4 | 4 |
<script src="../src/yoob/tape.js"></script>
|
5 | 5 |
<script src="../src/yoob/cursor.js"></script>
|
|
6 |
<script src="../src/yoob/tape-canvas-view.js"></script>
|
6 | 7 |
<style>
|
7 | 8 |
#canvas { border: 1px solid blue; }
|
8 | 9 |
</style>
|
|
17 | 18 |
|
18 | 19 |
<button id="write_0">Write 0</button>
|
19 | 20 |
<button id="write_1">Write 1</button>
|
|
21 |
<button id="read">Read</button>
|
20 | 22 |
<button id="left">Move Left</button>
|
21 | 23 |
<button id="right">Move Right</button>
|
22 | 24 |
|
23 | 25 |
</body>
|
24 | 26 |
<script>
|
25 | 27 |
var canvas = document.getElementById('canvas');
|
26 | |
var tape = new yoob.Tape();
|
27 | |
var th = new yoob.Cursor(0);
|
28 | |
th.tape = tape;
|
|
28 |
var head = new yoob.Cursor();
|
|
29 |
var tape = new yoob.Tape().init({ cursors: [head] });
|
|
30 |
var tcv = new yoob.TapeCanvasView().init({
|
|
31 |
tape: tape,
|
|
32 |
canvas: canvas
|
|
33 |
});
|
29 | 34 |
|
30 | 35 |
document.getElementById('write_0').onclick = function(e) {
|
31 | |
th.write("0");
|
32 | |
tape.drawCanvas(canvas, undefined, 20, [th]);
|
|
36 |
tape.write("0");
|
|
37 |
tcv.draw();
|
33 | 38 |
};
|
34 | 39 |
|
35 | 40 |
document.getElementById('write_1').onclick = function(e) {
|
36 | |
th.write("1");
|
37 | |
tape.drawCanvas(canvas, undefined, 20, [th]);
|
|
41 |
tape.write("1");
|
|
42 |
tcv.draw();
|
|
43 |
};
|
|
44 |
|
|
45 |
document.getElementById('read').onclick = function(e) {
|
|
46 |
alert(tape.read());
|
38 | 47 |
};
|
39 | 48 |
|
40 | 49 |
document.getElementById('left').onclick = function(e) {
|
41 | |
th.moveLeft();
|
42 | |
tape.drawCanvas(canvas, undefined, 20, [th]);
|
|
50 |
head.moveLeft();
|
|
51 |
tcv.draw();
|
43 | 52 |
};
|
44 | 53 |
|
45 | 54 |
document.getElementById('right').onclick = function(e) {
|
46 | |
th.moveRight();
|
47 | |
tape.drawCanvas(canvas, undefined, 20, [th]);
|
|
55 |
head.moveRight();
|
|
56 |
tcv.draw();
|
48 | 57 |
};
|
49 | 58 |
|
50 | 59 |
</script>
|