diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/asymptote/base/asymptote.py |
Initial commit
Diffstat (limited to 'graphics/asymptote/base/asymptote.py')
-rwxr-xr-x | graphics/asymptote/base/asymptote.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/graphics/asymptote/base/asymptote.py b/graphics/asymptote/base/asymptote.py new file mode 100755 index 0000000000..19b72c5082 --- /dev/null +++ b/graphics/asymptote/base/asymptote.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +# Python module to feed Asymptote with commands +# (modified from gnuplot.py) +from subprocess import * +class asy: + def __init__(self): + self.session = Popen(['asy','-quiet','-inpipe=0','-outpipe=2'],stdin=PIPE) + self.help() + def send(self, cmd): + self.session.stdin.write(bytes(cmd+'\n','utf-8')) + self.session.stdin.flush() + def size(self, size): + self.send("size(%d);" % size) + def draw(self, str): + self.send("draw(%s);" % str) + def fill(self, str): + self.send("fill(%s);" % str) + def clip(self, str): + self.send("clip(%s);" % str) + def label(self, str): + self.send("label(%s);" % str) + def shipout(self, str): + self.send("shipout(\"%s\");" % str) + def erase(self): + self.send("erase();") + def help(self): + print("Asymptote session is open. Available methods are:") + print(" help(), size(int), draw(str), fill(str), clip(str), label(str), shipout(str), send(str), erase()") + def __del__(self): + print("closing Asymptote session...") + self.send('quit'); + self.session.stdin.close(); + self.session.wait() + + + + + +if __name__=="__main__": + g = asy() + g.size(200) + g.draw("unitcircle") + g.send("draw(unitsquare)") + g.fill("unitsquare, blue") + g.clip("unitcircle") + g.label("\"$O$\", (0,0), SW") + raw_input("press ENTER to continue") + g.erase() + del g |