ASCII Line Art with Orgmode and Python
Topics
The last post was about converting ASCII line art into the SVG format within Emacs Orgmode using SvgBob. As versatile and may be a bit easier to use is Ascidia, which is written in Python. Ascidia renders to SVG and PNG.
Install Ascidia with:
pip install ascidia
Open Emacs, enter org-mode and load Babel-Python:
M-x load-library RET ob-python
Finally, use Ascidia to process your ASCII line art in your Orgmode code block:
#+BEGIN_SRC python :results value file :exports results import ascidia as asc diagram = asc.process_diagram("""\ .-----------------------------------. | .-----. .---------. .-----. | | / \/ \/ \ | | : / \ : | | \ : : / | | : | | : | | | | | | | | : | /\ /\ | : | | \ : : / | | '----\ /----' | | : : | | / \ ----- / \ | | / /: --- :\ \ | | +--' | | '--+ | | +---' : | | | / | | | / | | +--------' vep| '-----------------------------------' """) prefs = asc.OutputPrefs(fgcolour=asc.NAMED_COLOURS["blue"]) fname= './img/mastodon.png' with open(fname, 'wb') as stream: asc.PngOutput.output(diagram, stream, prefs) return(fname) #+END_SRC
Press C-c C-c
and get:
Next to having code and graphics in one file, I sometimes enjoy the restriction to only a few basic shapes, connectors and angles. This restriction enforces kind of a clean and tidy and reduced layout.
Have fun!