-
Notifications
You must be signed in to change notification settings - Fork 152
/
sample.html
345 lines (331 loc) · 11.6 KB
/
sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script type="text/javascript" src="simcir.js"></script>
<link rel="stylesheet" type="text/css" href="simcir.css" />
<script type="text/javascript" src="simcir-basicset.js"></script>
<link rel="stylesheet" type="text/css" href="simcir-basicset.css" />
<script type="text/javascript" src="simcir-library.js"></script>
<style type="text/css">
* {
font-family: arial, sans-serif;
}
.code {
margin: 16px 0px 16px 0px;
padding: 4px;
border-width: 0px 0px 0px 4px;
border-color: #cccccc;
border-style: solid;
background-color: #f0f0f0;
white-space: pre;
}
.note {
color: #0000ff;
}
</style>
<title>SimcirJS</title>
</head>
<body>
<h1>SimcirJS</h1>
<div style="margin:16px 0px 16px 0px">
SimcirJS(a.k.a. Simcir) is a circuit simulator in HTML5 and JavaScript.
<br/>
Let's try your circuit!
</div>
<h2>Usage</h2>
<ul>
<li>Choose a device from the toolbox and move to right side.</li>
<li>Connect them by drag operation.</li>
<li>Click an input node to disconnect.</li>
<li>Move a device back to the toolbox if you don't use.</li>
<li>Ctrl+Click(Mac:command+Click) to toggle view (Live circuit or JSON data).</li>
<li>Double-Click a label to edit device name.</li>
<li>Double-Click a library to open the circuit inside.</li>
</ul>
<!--
Specify width and height only.
All the other attributes will be used defaults.
-->
<div class="simcir">
{
"width":800,
"height":400
}
</div>
<h2>Embed your circuit</h2>
<p>
Ctrl+Click(Mac:command+Click) on your circuit and copy a circuit data.
<br/>
Then paste it into template below.
</p>
<div class="code"
><!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script type="text/javascript" src="simcir.js"></script>
<link rel="stylesheet" type="text/css" href="simcir.css" />
<script type="text/javascript" src="simcir-basicset.js"></script>
<link rel="stylesheet" type="text/css" href="simcir-basicset.css" />
<script type="text/javascript" src="simcir-library.js"></script>
<title></title>
</head>
<body>
<div class="simcir">
<span class="note"><!-- paste here your circuit data --></span>
</div>
</body>
</html>
</div>
<h2>Reuse your circuit</h2>
<p>
To reuse your circuit as library, use device 'In' and 'Out'.
</p>
<div class="simcir">
{
"width":500,
"height":200,
"showToolbox":true,
"toolbox":[
{"type":"In"},
{"type":"Out"},
{"type":"DC"},
{"type":"PushOff"},
{"type":"PushOn"},
{"type":"Toggle"},
{"type":"NAND"}
],
"devices":[
{"type":"DC","id":"dev0","x":64,"y":80,"label":"DC"},
{"type":"PushOff","id":"dev1","x":120,"y":48,"label":"PushOff"},
{"type":"PushOff","id":"dev2","x":120,"y":112,"label":"PushOff"},
{"type":"In","id":"dev3","x":176,"y":48,"label":"~S"},
{"type":"In","id":"dev4","x":176,"y":112,"label":"~R"},
{"type":"NAND","id":"dev5","x":232,"y":56,"label":"NAND"},
{"type":"NAND","id":"dev6","x":232,"y":104,"label":"NAND"},
{"type":"Out","id":"dev7","x":288,"y":56,"label":"Q"},
{"type":"Out","id":"dev8","x":288,"y":104,"label":"~Q"}
],
"connectors":[
{"from":"dev1.in0","to":"dev0.out0"},
{"from":"dev2.in0","to":"dev0.out0"},
{"from":"dev3.in0","to":"dev1.out0"},
{"from":"dev4.in0","to":"dev2.out0"},
{"from":"dev5.in0","to":"dev3.out0"},
{"from":"dev5.in1","to":"dev6.out0"},
{"from":"dev6.in0","to":"dev5.out0"},
{"from":"dev6.in1","to":"dev4.out0"},
{"from":"dev7.in0","to":"dev5.out0"},
{"from":"dev8.in0","to":"dev6.out0"}
]
}
</div>
<p>
Then register it in JavaScript and add to the toolbox in HTML.
</p>
<div class="code"
>simcir.registerDevice('<span class="note">MyDevice</span>',
<span class="note">// paste here your circuit data</span>
);
</div>
<div class="code"
><div class="simcir">
⋮
"toolbox":[
{"type":"DC"},
{"type":"PushOff"},
⋮
{"type":"<span class="note">MyDevice</span>"}
],
⋮
</div>
</div>
<p>
In this case, a new device 'RS-FF' is added.
Try to Double-Click the 'RS-FF' :)
<br/>
Remember that all the connectors on
an input of 'In' and an output of 'Out'
are disconnected internally when the device is reused.
</p>
<div class="simcir">
{
"width":500,
"height":200,
"showToolbox":true,
"toolbox":[
{"type":"DC"},
{"type":"PushOff"},
{"type":"RS-FF"}
],
"devices":[
{"type":"DC","id":"dev0","x":104,"y":80,"label":"DC"},
{"type":"PushOff","id":"dev1","x":160,"y":48,"label":"PushOff"},
{"type":"PushOff","id":"dev2","x":160,"y":112,"label":"PushOff"},
{"type":"RS-FF","id":"dev3","x":216,"y":80,"label":"RS-FF"}
],
"connectors":[
{"from":"dev1.in0","to":"dev0.out0"},
{"from":"dev2.in0","to":"dev0.out0"},
{"from":"dev3.in0","to":"dev1.out0"},
{"from":"dev3.in1","to":"dev2.out0"}
]
}
</div>
<p>
To customize the layout of library,
add the "layout" property to your device with a text editor.
<br/>
"rows" and "cols" define the size.
nodes property contains 'label - position' pairs of nodes.
</p>
<div class="code"
>simcir.registerDevice('AltFullAdder',
{
⋮
<span class="note">"layout":{"rows":8,"cols":8,"hideLabelOnWorkspace":true,</span>
<span class="note">"nodes":{"A":"T2","B":"T6","S":"B4","Cin":"R4","Cout":"L4"}},</span>
"devices":[
⋮
</div>
<!-- port from drawing of Illustrator. -->
<svg version="1.1" id="l_1_" xmlns="http://www.w3.org/2000/svg"
width="234px" height="168px" viewBox="198 159 234 168"
font-size="12" >
<rect id="p_1_" x="198.5" y="159.5" fill="#FFFFFF" stroke="#666666"
stroke-miterlimit="10" width="233" height="167"/>
<g id="l">
<g id="g_3_">
<text transform="matrix(1 0 0 1 264.6001 238.0002)" >L1</text>
<text transform="matrix(1 0 0 1 264.6001 220.0002)" fill="#999999" >L0</text>
<text transform="matrix(1 0 0 1 264.6001 256.0002)" >L2</text>
<text transform="matrix(1 0 0 1 264.6001 274.0002)" >L3</text>
<text transform="matrix(1 0 0 1 264.6001 292.0002)" fill="#999999" >L4</text>
<text transform="matrix(1 0 0 1 280.8003 207.0002)" fill="#999999" >T0</text>
<text transform="matrix(1 0 0 1 298.8003 207.0002)" >T1</text>
<text transform="matrix(1 0 0 1 316.8003 207.0002)" >T2</text>
<text transform="matrix(1 0 0 1 334.8003 207.0002)" >T3</text>
<text transform="matrix(1 0 0 1 352.8003 207.0002)" fill="#999999" >T4</text>
<text transform="matrix(1 0 0 1 369 220.0002)" fill="#999999" >R0</text>
<text transform="matrix(1 0 0 1 369 238.0002)" >R1</text>
<text transform="matrix(1 0 0 1 369 256.0002)" >R2</text>
<text transform="matrix(1 0 0 1 369 274.0002)" >R3</text>
<text transform="matrix(1 0 0 1 369 292.0002)" fill="#999999" >R4</text>
<text transform="matrix(1 0 0 1 280.8003 306.0002)" fill="#999999" >B0</text>
<text transform="matrix(1 0 0 1 298.8003 306.0002)" >B1</text>
<text transform="matrix(1 0 0 1 316.8003 306.0002)" >B2</text>
<text transform="matrix(1 0 0 1 334.8003 306.0002)" >B3</text>
<text transform="matrix(1 0 0 1 352.8003 306.0002)" fill="#999999" >B4</text>
</g>
</g>
<g id="g_2_">
<g id="g_1_">
<path id="p" fill="#CCCCCC" stroke="#666666" stroke-miterlimit="10"
d="M360,282.331c0,3.131-2.538,5.669-5.669,5.669h-60.662
c-3.131,0-5.669-2.538-5.669-5.669V221.67
c0-3.131,2.538-5.669,5.669-5.669h60.662
c3.131,0,5.669,2.538,5.669,5.669V282.331z"/>
<g id="g">
<line fill="none" stroke="#666666" stroke-miterlimit="10" x1="306" y1="216" x2="306" y2="288"/>
<line fill="none" stroke="#666666" stroke-miterlimit="10" x1="324" y1="216" x2="324" y2="288"/>
<line fill="none" stroke="#666666" stroke-miterlimit="10" x1="342" y1="216" x2="342" y2="288"/>
<line fill="none" stroke="#666666" stroke-miterlimit="10" x1="360" y1="234" x2="288" y2="234"/>
<line fill="none" stroke="#666666" stroke-miterlimit="10" x1="288" y1="252" x2="360" y2="252"/>
<line fill="none" stroke="#666666" stroke-miterlimit="10" x1="360" y1="270" x2="288" y2="270"/>
</g>
</g>
</g>
<g id="g1">
<text transform="matrix(1 0 0 1 229.2002 256.0002)" >Left</text>
<text transform="matrix(1 0 0 1 389 256.0002)" >Right</text>
<text transform="matrix(1 0 0 1 302.4004 322.0002)" >Bottom</text>
<text transform="matrix(1 0 0 1 313.2002 191.0002)" >Top</text>
<g id="g3">
<text transform="matrix(1 0 0 1 208.8174 211.0002)" >rows</text>
<g>
<g>
<polygon points="218.717,225 223.217,216 227.717,225 "/>
<polygon points="223.217,288 227.717,279 218.717,279 "/>
<path stroke="#000000" stroke-width="4"
stroke-miterlimit="10" d="M223.217,225v54V225z"/>
</g>
<line fill="none" stroke="#000000" stroke-width="0.5"
stroke-miterlimit="10" x1="209.717" y1="216" x2="236.717" y2="216"/>
<line fill="none" stroke="#000000" stroke-width="0.5"
stroke-miterlimit="10" x1="209.717" y1="288" x2="236.717" y2="288"/>
</g>
</g>
<g id="g2">
<text transform="matrix(1 0 0 1 255.6001 180.0803)" >cols</text>
<g>
<g>
<polygon points="297,182 288,177.5 297,173 "/>
<polygon points="360,177.5 351,173 351,182 "/>
<path stroke="#000000" stroke-width="4"
stroke-miterlimit="10" d="M297,177.5h54H297z"/>
</g>
<line fill="none" stroke="#000000" stroke-width="0.5"
stroke-miterlimit="10" x1="288" y1="164" x2="288" y2="191"/>
<line fill="none" stroke="#000000" stroke-width="0.5"
stroke-miterlimit="10" x1="360" y1="164" x2="360" y2="191"/>
</g>
</g>
</g>
</svg>
<h2>Customize a device</h2>
<p>
label, color, number of inputs, freq ...
</p>
<div class="simcir">
{
"width":500,
"height":400,
"showToolbox":true,
"toolbox":[
{"type":"DC"},
{"type":"Toggle"},
{"type":"LED","color":"#00ff00","label":"LED(G)"},
{"type":"NAND","numInputs":"3","label":"NAND(3in)"},
{"type":"OSC","freq":1,"label":"OSC(1Hz)"},
{"type":"7seg","color":"#000000","bgColor":"#889988"}
],
"devices":[
{"type":"NAND","numInputs":"3","label":"NAND(3in)","id":"dev0","x":208,"y":128},
{"type":"Toggle","id":"dev1","x":152,"y":80,"label":"Toggle"},
{"type":"Toggle","id":"dev2","x":152,"y":128,"label":"Toggle"},
{"type":"Toggle","id":"dev3","x":152,"y":176,"label":"Toggle"},
{"type":"DC","id":"dev4","x":96,"y":128,"label":"DC"},
{"type":"LED","color":"#00ff00","label":"LED(G)","id":"dev5","x":264,"y":128},
{"type":"OSC","freq":1,"label":"OSC(1Hz)","id":"dev6","x":96,"y":232},
{"type":"NAND","numInputs":"3","label":"NAND(3in)","id":"dev7","x":152,"y":272},
{"type":"7seg","color":"#000000","bgColor":"#889988","id":"dev8","x":208,"y":232,"label":"7seg"}
],
"connectors":[
{"from":"dev0.in0","to":"dev1.out0"},
{"from":"dev0.in1","to":"dev2.out0"},
{"from":"dev0.in2","to":"dev3.out0"},
{"from":"dev1.in0","to":"dev4.out0"},
{"from":"dev2.in0","to":"dev4.out0"},
{"from":"dev3.in0","to":"dev4.out0"},
{"from":"dev5.in0","to":"dev0.out0"},
{"from":"dev7.in0","to":"dev6.out0"},
{"from":"dev7.in1","to":"dev6.out0"},
{"from":"dev7.in2","to":"dev6.out0"},
{"from":"dev8.in0","to":"dev6.out0"},
{"from":"dev8.in1","to":"dev7.out0"},
{"from":"dev8.in2","to":"dev7.out0"},
{"from":"dev8.in3","to":"dev6.out0"},
{"from":"dev8.in4","to":"dev7.out0"},
{"from":"dev8.in5","to":"dev7.out0"},
{"from":"dev8.in6","to":"dev6.out0"}
]
}
</div>
<div class="simcir-doc"></div>
<hr/>
<div style="text-align: right;">
Contents Copyright © Kazuhiko Arase
</div>
</body>
</html>