2 <title>Digital Logic Simulator
</title>
5 var grid_status
= 1; /* boolean status of stage grid lines */
6 var grid_size
= 20; /* this is stored here for reference */
7 var canvas
; /* object id of canvas tag */
8 var ctx
; /* context of canvas */
9 var item_selected
= "gate_and" /* only one type of object can be drawn at a time */
11 /* intial setup of page - must be called on page load */
14 /* initalize canvas element for use */
15 canvas
= document
.getElementById("stage");
16 ctx
= canvas
.getContext("2d");
17 /* get width and height of window and set stage (canvas) with it. */
18 canvas
.height
= window
.innerHeight
-125;
19 canvas
.width
= window
.innerWidth
- 45;
20 if(grid_status
) {draw_grid(); }
25 /* draw faint gridlines on stage - used as a guide for the user */
29 for(x
= 0; x
< window
.innerWidth
; x
++)
35 function draw_and_gate(x
,y
)
37 //if(!x || !y) { alert("Coordinates Not Sent to Function"); return; }
42 ctx
.arc(75,75,35,0,Math
.PI
,false);
46 /* user changes what type of gate will be drawn next */
47 function change_selection(sel
)
49 var button
= document
.getElementById(sel
);
50 if(!button
) { alert("Cannot Find Selected Button"); return; }
51 /* enable old button */
52 document
.getElementById(item_selected
).disabled
= false;
53 /* disable new button */
54 button
.disabled
= true;
61 <style type=
"text/css">
64 border: solid
1px #000;
68 <body onLoad=
"init_form();">
70 <center><h2>Digital Logic Simulator
</h2></center>
72 <button id=
"gate_and" onClick='change_selection(
"gate_and");' disabled
>AND
</button>
74 <button id=
"gate_or" onClick='change_selection(
"gate_or");'
>OR
</button>
76 <button id=
"gate_not" onClick='change_selection(
"gate_not");'
>NOT
</button>
78 <button id=
"gate_nor" onClick='change_selection(
"gate_nor");'
>NOR
</button>
80 <button id=
"gate_xor" onClick='change_selection(
"gate_xor");'
>XOR
</button>
82 <button id=
"gate_connect" onClick='change_selection(
"gate_connect");'
>Connect
</button>
86 <canvas id=
"stage" width=
"200" height=
"200">
87 Your browser does not support HTML5 Canvas.