git @ Cat's Eye Technologies Flobnar / 20c5fda
Add some example programs. Load them in the web-based demo. Chris Pressey 3 years ago
9 changed file(s) with 106 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
0 document.getElementById('installation').innerHTML = (
1 '<textarea id="prog" rows="10" cols="80"></textarea>' +
2 '<div><button id="run-button">Run</button></div>' +
3 '<pre id="result"></pre>'
4 );
0 function launch(config) {
1 config.container.innerHTML = `
2 <textarea id="prog" rows="10" cols="80"></textarea>
3 <div id="control-panel"></div>
4 <div><button id="run-button">Run</button></div>
5 <pre id="result"></pre>
6 `;
7
8 function makeSelect(container, labelText, optionsArray, fun) {
9 var label = document.createElement('label');
10 label.innerHTML = labelText;
11 container.appendChild(label);
12 var select = document.createElement("select");
13 for (var i = 0; i < optionsArray.length; i++) {
14 var op = document.createElement("option");
15 op.text = optionsArray[i].filename;
16 op.value = optionsArray[i].contents;
17 select.options.add(op);
18 }
19 select.onchange = function(e) {
20 fun(optionsArray[select.selectedIndex]);
21 };
22 select.selectedIndex = 0;
23 label.appendChild(select);
24 return select;
25 };
26
27 function selectOptionByText(selectElem, text) {
28 var optElem;
29 for (var i = 0; optElem = selectElem.options[i]; i++) {
30 if (optElem.text === text) {
31 selectElem.selectedIndex = i;
32 selectElem.dispatchEvent(new Event('change'));
33 return;
34 }
35 }
36 }
37
38 var controlPanel = document.getElementById('control-panel');
39 var select = makeSelect(controlPanel, "example program:", examplePrograms, function(option) {
40 document.getElementById('prog').value = option.contents;
41 });
42 selectOptionByText(select, "factorial.flobnar");
43 }
44
45 launch({ container: document.getElementById('installation') });
1010
1111 <div id="installation"></div>
1212
13 <script src="../eg/examplePrograms.jsonp.js"></script>
1314 <script src="flobnar-hastec-launcher.js"></script>
1415 <script src="flobnar.js"></script>
1516 </body>
0 3
1 *>
2 9+@
3 />
4 2
0 >>>>>v
1 ^ v
2 ^ 4
3 ^<<<<@
0 examplePrograms = [
1 {
2 "contents": "3\n*>\n9+@\n/>\n2\n",
3 "filename": "arithmetic.flobnar"
4 },
5 {
6 "contents": ">>>>>v\n^ v\n^ 4\n^<<<<@\n",
7 "filename": "arrows.flobnar"
8 },
9 {
10 "contents": "> v\n^\\ < \n \n:v v \\<@\n-< : 6\n1 : > *\n -| <\n 11\n",
11 "filename": "factorial.flobnar"
12 },
13 {
14 "contents": " 3\n\n9 | @\n\n 4\n",
15 "filename": "if.flobnar"
16 },
17 {
18 "contents": " 5\n85 #\n*p<\n40+@\n > ^\n 6\n 9\n",
19 "filename": "self-mod.flobnar"
20 },
21 {
22 "contents": " \n v @ \n #< 17 \n \n",
23 "filename": "wrapping.flobnar"
24 }
25 ];
0 > v
1 ^\ <
2
3 :v v \<@
4 -< : 6
5 1 : > *
6 -| <
7 11
0 3
1
2 9 | @
3
4 4
0 5
1 85 #
2 *p<
3 40+@
4 > ^
5 6
6 9
0
1 v @
2 #< 17
3