Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / okg-prac-helper.js
diff options
context:
space:
mode:
Commita37b379f9e44653b2c12ed748a1e1b6d09f50c22 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-10-03 15:10:34 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-10-03 15:10:34 +0300
Files08653f7e6d22b64343d9958e973b76602db22cbd /Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
uni-projects-a37b379f9e44653b2c12ed748a1e1b6d09f50c22.tar
uni-projects-a37b379f9e44653b2c12ed748a1e1b6d09f50c22.tar.gz
uni-projects-a37b379f9e44653b2c12ed748a1e1b6d09f50c22.zip
Parentecaaedc00cbaee76ef67f2d468e00a629819f3f1 (diff)
[OKG] Added a practicum template for the future, and added needed javascript files
1 files changed, 40 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics Fundamentals/okg-prac-helper.js40
diff --git a/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
new file mode 100644
index 0000000..58c12a2
--- /dev/null
+++ b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
@@ -0,0 +1,40 @@
+/* Create
+ * <nav id="scrCont"><select id="scrSel"></select></nav>
+ */
+
+const scrCont = document.createElement('nav');
+scrCont.id = 'scrCont';
+document.body.insertBefore(scrCont, document.body.firstChild);
+
+const scrSel = document.createElement('select');
+scrSel.id = 'scrSel';
+scrCont.appendChild(scrSel);
+
+/* Add options to scrSel, from scripts array */
+
+for (var i = 0; i < scripts.length; i++) {
+ var temp = document.createElement('option');
+ temp.value = i;
+ temp.text = scripts[i][0];
+ scrSel.appendChild(temp);
+}
+
+
+/* Logic for changing rendered object */
+
+function renderScr (index) {
+ var temp = document.createElement('script');
+ temp.src = scripts[index][1];
+ temp.id = scripts[index][1];
+ document.body.appendChild(temp);
+}
+
+var oldIndex = scrSel.value;
+renderScr(scrSel.value);
+
+scrSel.onchange = function() {
+ document.body.removeChild(document.getElementById(scripts[oldIndex][1]));
+ document.body.removeChild(document.getElementsByTagName('canvas')[0]);
+ renderScr(scrSel.value);
+ oldIndex = scrSel.value;
+}