Content-Length: 5932 | pFad | https://vennemann-online.de/flossblog/post20250223_ascidia.html

ASCII Line Art with Orgmode and Python

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= './ellie.png'
with open(fname, 'wb') as stream:
    asc.PngOutput.output(diagram, stream, prefs)
return(fname)
#+END_SRC

Press C-c C-c and get:

ellie.png

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, tidy and reduced layout.

Let's have fun, and make a mastodon variant. Improve it, if you like!

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)

mastodon.png

Datum: February 23 2025

Autor: Peter Vennemann

Email: mail@vennemann-online.de









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://vennemann-online.de/flossblog/post20250223_ascidia.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy