From 3336eee268190a761fa3fa3efaea5918f64a0318 Mon Sep 17 00:00:00 2001 From: skylarmt Date: Thu, 15 Jan 2015 03:10:11 -0700 Subject: [PATCH] more things --- src/net/apocalypselabs/symat/CodeRunner.java | 20 ++++----- src/net/apocalypselabs/symat/functions.py | 42 +++++++++++++++++++ .../symat/resources/jsfunctions.txt | 3 -- .../symat/resources/pyfunctions.txt | 3 -- 4 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 src/net/apocalypselabs/symat/functions.py diff --git a/src/net/apocalypselabs/symat/CodeRunner.java b/src/net/apocalypselabs/symat/CodeRunner.java index 291fd44..c197032 100644 --- a/src/net/apocalypselabs/symat/CodeRunner.java +++ b/src/net/apocalypselabs/symat/CodeRunner.java @@ -67,7 +67,7 @@ public class CodeRunner { // Add custom functions. se.eval("importClass(net.apocalypselabs.symat.Functions);" + "SyMAT_Functions = new net.apocalypselabs.symat.Functions();" - + jsFunctions()); + + getFunctions("js")); } catch (Exception ex) { initError(ex); } @@ -75,7 +75,10 @@ public class CodeRunner { case "python": se = new ScriptEngineManager().getEngineByName("python"); try { - se.eval("from math import *\nfrom net.apocalypselabs.symat import Functions\n_=Functions()\n"); + se.eval("from math import *\n" + + "from net.apocalypselabs.symat import Functions\n" + + "_=Functions()\n\n" + + getFunctions("py")); } catch (Exception ex) { initError(ex); } @@ -160,13 +163,13 @@ public class CodeRunner { return se.get(var); } - private String jsFunctions() { + private String getFunctions(String lang) { String text = ""; try { BufferedReader reader = new BufferedReader( new InputStreamReader( CodeRunner.class - .getResourceAsStream("functions.js"))); + .getResourceAsStream("functions."+lang))); String line; while ((line = reader.readLine()) != null) { text += line; @@ -175,13 +178,4 @@ public class CodeRunner { } return text; } - - // TODO: Run Javascript in separate thread from rest of app. - private class JsThread extends Thread { - - @Override - public void run() { - - } - } } diff --git a/src/net/apocalypselabs/symat/functions.py b/src/net/apocalypselabs/symat/functions.py new file mode 100644 index 0000000..203609e --- /dev/null +++ b/src/net/apocalypselabs/symat/functions.py @@ -0,0 +1,42 @@ +'''def notify(msg): + _.notify(msg) + +def ask(msg): + return _.ask(msg) + +def diff(fun,var): + return _.diff(fun,var) + +def integrate(fun,var): + return _.integrate(fun,var) + +def rad(num): + return _.rad(num) + +def deg(num): + return _.deg(num) + +def subs(fun,var): + return _.subs(fun,var) + +def plot(): + _.plot() + +def plot(fun): + _.plot(fun) + +def plotname(fun): + _.plotname(fun) + +def plotname(): + return _.plotname() + +def xlim(min,max): + _.xlim(min,max) + +def plotclr(): + _.plotclr() + +def drawdot(x, y): + _.drawdot(x, y) +''' \ No newline at end of file diff --git a/src/net/apocalypselabs/symat/resources/jsfunctions.txt b/src/net/apocalypselabs/symat/resources/jsfunctions.txt index dbe8d17..e7c04f4 100644 --- a/src/net/apocalypselabs/symat/resources/jsfunctions.txt +++ b/src/net/apocalypselabs/symat/resources/jsfunctions.txt @@ -7,13 +7,10 @@ deg(0)|Convert a given number in radians to degrees. subs('',"x")|Solve an equation for the second argument. plot()|Show the plot window. plot('')|Graph the given function. -plot(x[],y[])|Graph the lists of points given. -graph('')|Alias of plot('') plotname("")|Sets the title of the graph window. plotname()|Gets the title of the graph window. xlim(min,max)|Sets the x-axis min and max values. Cannot be used after a formula has been graphed. plotclr()|Reset the graph. -clearplot()|Alias of plotclr() drawdot(x, y)|Places a dot at the given coordinates. abs(0)|Absolute value of number. asin(0)| diff --git a/src/net/apocalypselabs/symat/resources/pyfunctions.txt b/src/net/apocalypselabs/symat/resources/pyfunctions.txt index 60f7350..5b9d496 100644 --- a/src/net/apocalypselabs/symat/resources/pyfunctions.txt +++ b/src/net/apocalypselabs/symat/resources/pyfunctions.txt @@ -7,13 +7,10 @@ _.deg(0)|Convert a given number in radians to degrees. _.subs('',"x")|Solve an equation for the second argument. _.plot()|Show the plot window. _.plot('')|Graph the given function. -_.plot(x[],y[])|Graph the lists of points given. -_.graph('')|Alias of plot('') _.plotname("")|Sets the title of the graph window. _.plotname()|Gets the title of the graph window. _.xlim(min,max)|Sets the x-axis min and max values. Cannot be used after a formula has been graphed. _.plotclr()|Reset the graph. -_.clearplot()|Alias of plotclr() _.drawdot(x, y)|Places a dot at the given coordinates. fabs(0)|Absolute value of number. asin(0)|