more things
This commit is contained in:
parent
9e7b64740d
commit
3336eee268
@ -67,7 +67,7 @@ public class CodeRunner {
|
|||||||
// Add custom functions.
|
// Add custom functions.
|
||||||
se.eval("importClass(net.apocalypselabs.symat.Functions);"
|
se.eval("importClass(net.apocalypselabs.symat.Functions);"
|
||||||
+ "SyMAT_Functions = new net.apocalypselabs.symat.Functions();"
|
+ "SyMAT_Functions = new net.apocalypselabs.symat.Functions();"
|
||||||
+ jsFunctions());
|
+ getFunctions("js"));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
initError(ex);
|
initError(ex);
|
||||||
}
|
}
|
||||||
@ -75,7 +75,10 @@ public class CodeRunner {
|
|||||||
case "python":
|
case "python":
|
||||||
se = new ScriptEngineManager().getEngineByName("python");
|
se = new ScriptEngineManager().getEngineByName("python");
|
||||||
try {
|
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) {
|
} catch (Exception ex) {
|
||||||
initError(ex);
|
initError(ex);
|
||||||
}
|
}
|
||||||
@ -160,13 +163,13 @@ public class CodeRunner {
|
|||||||
return se.get(var);
|
return se.get(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String jsFunctions() {
|
private String getFunctions(String lang) {
|
||||||
String text = "";
|
String text = "";
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(
|
BufferedReader reader = new BufferedReader(
|
||||||
new InputStreamReader(
|
new InputStreamReader(
|
||||||
CodeRunner.class
|
CodeRunner.class
|
||||||
.getResourceAsStream("functions.js")));
|
.getResourceAsStream("functions."+lang)));
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
text += line;
|
text += line;
|
||||||
@ -175,13 +178,4 @@ public class CodeRunner {
|
|||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Run Javascript in separate thread from rest of app.
|
|
||||||
private class JsThread extends Thread {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
42
src/net/apocalypselabs/symat/functions.py
Normal file
42
src/net/apocalypselabs/symat/functions.py
Normal file
@ -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)
|
||||||
|
'''
|
@ -7,13 +7,10 @@ deg(0)|Convert a given number in radians to degrees.
|
|||||||
subs('',"x")|Solve an equation for the second argument.
|
subs('',"x")|Solve an equation for the second argument.
|
||||||
plot()|Show the plot window.
|
plot()|Show the plot window.
|
||||||
plot('')|Graph the given function.
|
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("")|Sets the title of the graph window.
|
||||||
plotname()|Gets 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.
|
xlim(min,max)|Sets the x-axis min and max values. Cannot be used after a formula has been graphed.
|
||||||
plotclr()|Reset the graph.
|
plotclr()|Reset the graph.
|
||||||
clearplot()|Alias of plotclr()
|
|
||||||
drawdot(x, y)|Places a dot at the given coordinates.
|
drawdot(x, y)|Places a dot at the given coordinates.
|
||||||
abs(0)|Absolute value of number.
|
abs(0)|Absolute value of number.
|
||||||
asin(0)|
|
asin(0)|
|
||||||
|
@ -7,13 +7,10 @@ _.deg(0)|Convert a given number in radians to degrees.
|
|||||||
_.subs('',"x")|Solve an equation for the second argument.
|
_.subs('',"x")|Solve an equation for the second argument.
|
||||||
_.plot()|Show the plot window.
|
_.plot()|Show the plot window.
|
||||||
_.plot('')|Graph the given function.
|
_.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("")|Sets the title of the graph window.
|
||||||
_.plotname()|Gets 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.
|
_.xlim(min,max)|Sets the x-axis min and max values. Cannot be used after a formula has been graphed.
|
||||||
_.plotclr()|Reset the graph.
|
_.plotclr()|Reset the graph.
|
||||||
_.clearplot()|Alias of plotclr()
|
|
||||||
_.drawdot(x, y)|Places a dot at the given coordinates.
|
_.drawdot(x, y)|Places a dot at the given coordinates.
|
||||||
fabs(0)|Absolute value of number.
|
fabs(0)|Absolute value of number.
|
||||||
asin(0)|
|
asin(0)|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user