{ "name": "Graphing Calculator", "icon": "\u{1F4C8}\uFE0E", "desc": "A graphing calculator with many useful tools.", "id": "graph-calc", "globalID": "GopalOS.GraphingCalculator", "defaultRelease": "beta", "releases": { "beta": { "version": "v1.1.0-beta.14", "app-files": { "graph-calc": { type: "pgm", content: function() { if (document.getElementById("app_graph-calc_window")) { document.getElementById("app_graph-calc_window").style.display = "block"; } else { document.getElementById("windows").insertAdjacentHTML("beforeend", getRef("/apps/graph-calc/window")); getRef("/apps/graph-calc/load")(); } focusWin(document.getElementById("app_graph-calc_window")); regTbarIcon("/apps/graph-calc/graph-calc", "app_graph-calc_window", "\u{1F4C8}\uFE0E"); refreshWindows(); } }, "dims": { type: "var", content: [1000, 1000] }, "origin": { type: "var", content: [500, 500] }, "px-per-unit": { type: "var", content: 50 }, "load": { type: "js", content: function() { getRef("/apps/graph-calc/init")(); } }, "init": { type: "js", content: function() { let [cWidth, cHeight] = getRef("/apps/graph-calc/dims"); let [originX, originY] = getRef("/apps/graph-calc/origin"); let pxPerUnit = getRef("/apps/graph-calc/px-per-unit"); let ctx = document.getElementById("app_graph-calc_canvas").getContext("2d"); ctx.clearRect(0, 0, cWidth, cHeight); ctx.strokeStyle = "#DDD"; ctx.lineWidth = 1; let gridItvl = 1; for (let i = 1; i < (cWidth / pxPerUnit); i++) { let gridline = new Path2D(); gridline.moveTo(originX - (i * pxPerUnit * gridItvl), 0); gridline.lineTo(originX - (i * pxPerUnit * gridItvl), cHeight); gridline.moveTo(originX + (i * pxPerUnit * gridItvl), 0); gridline.lineTo(originX + (i * pxPerUnit * gridItvl), cHeight); ctx.stroke(gridline); } for (let i = 1; i < (cHeight / pxPerUnit); i++) { let gridline = new Path2D(); gridline.moveTo(0, originY - (i * pxPerUnit * gridItvl)); gridline.lineTo(cWidth, originY - (i * pxPerUnit * gridItvl)); gridline.moveTo(0, originY + (i * pxPerUnit * gridItvl)); gridline.lineTo(cWidth, originY + (i * pxPerUnit * gridItvl)); ctx.stroke(gridline); } ctx.strokeStyle = "#000"; ctx.lineWidth = 2; let axes = new Path2D(); axes.moveTo(0, cHeight - originY); axes.lineTo(cWidth, cHeight - originY); axes.moveTo(originX, 0); axes.lineTo(originX, cHeight); ctx.stroke(axes); } }, "conv-coords": { type: "js", content: function(coords) { let [cWidth, cHeight] = getRef("/apps/graph-calc/dims"); let [originX, originY] = getRef("/apps/graph-calc/origin"); let pxPerUnit = getRef("/apps/graph-calc/px-per-unit"); return [ coords[0] * pxPerUnit + originX - 1, cHeight - (coords[1] * pxPerUnit + originY - 1) ]; } }, "graph": { type: "js", content: function(funcArr, domain = null, type = "func") { let [cWidth, cHeight] = getRef("/apps/graph-calc/dims"); let [originX, originY] = getRef("/apps/graph-calc/origin"); let pxPerUnit = getRef("/apps/graph-calc/px-per-unit"); let ctx = document.getElementById("app_graph-calc_canvas").getContext("2d"); ctx.fillStyle = "#1E90FF"; if (type == "parm") { let x, y; eval(`x = function(t) {with (Math) {return (${funcArr[0]});}};`); eval(`y = function(t) {with (Math) {return (${funcArr[1]});}};`); for (let i = domain[0]; i <= domain[1]; i += (1 / 500)) { ctx.fillRect( ...getRef("/apps/graph-calc/conv-coords")([x(i), y(i)]), 2, 2 ); } } else if (type == "polr") { let r, theta; eval(`r = function(t) {with (Math) {return (${funcArr[0]});}};`); eval(`theta = function(t) {with (Math) {return (${funcArr[1]});}};`); for (let i = domain[0]; i <= domain[1]; i += (1 / 500)) { ctx.fillRect( ...getRef("/apps/graph-calc/conv-coords")([r(i) * Math.cos(theta(i)), r(i) * Math.sin(theta(i))]), 2, 2 ); } } else { let f; eval(`f = function(x) {with (Math) {return (${funcArr[0]});}};`); for (let i = -100; i <= 100; i += (1 / 500)) { ctx.fillRect( ...getRef("/apps/graph-calc/conv-coords")([i, f(i)]), 2, 2 ); } } } }, "graph-all": { type: "js", content: function() { getRef("/apps/graph-calc/init")(); for (let i = 0; i < document.getElementById("app_graph-calc_sidebar").children.length - 1; i++) { document.getElementById("app_graph-calc_sidebar").children[i].classList.remove("app_graph-calc_item-invalid"); let inputs = [...document.getElementById("app_graph-calc_sidebar").children[i].getElementsByClassName("app_graph-calc_item-input")].map(elem => elem.value); try { if (document.getElementById("app_graph-calc_sidebar").children[i].getAttribute("data-functype") == "parm") { getRef("/apps/graph-calc/graph")([inputs[0], inputs[1]], [Number(inputs[2]), Number(inputs[3])], "parm"); } else if (document.getElementById("app_graph-calc_sidebar").children[i].getAttribute("data-functype") == "polr") { getRef("/apps/graph-calc/graph")([inputs[0], inputs[1]], [Number(inputs[2]), Number(inputs[3])], "polr"); } else { getRef("/apps/graph-calc/graph")([inputs[0]]); } } catch(err) { document.getElementById("app_graph-calc_sidebar").children[i].classList.add("app_graph-calc_item-invalid"); } } } }, "clear-all": { type: "js", content: function() { document.getElementById("app_graph-calc_sidebar").innerHTML = `