The Stomachion, rendered using NanoVG-REPL
Last year, I tried an experiment. I wanted to see how easy it would be to do standard 2D graphics from Scheme, but not through a foreign function interface. For the application I had in mind, low refresh rates would be just fine, so I decided to try communicating with a graphics library using a text protocol over a pipe. NanoVG-REPL is the result of that experiment.
Using a text protocol made porting from language to language a breeze. I even tried doing graphics from Bash.
For simple animations, NanoVG-REPL can reach more than two hundred frames per second on my laptop. But the graphics primitives are universal, so if performance becomes an issue, it should be possible to port a program to another, faster library that does use an FFI.
NanoVG-REPL is a wrapper around NanoVG, a small antialiased vector graphics rendering library for OpenGL. I provides a Read-Eval-Print Loop for running NanoVG commands. To use it, just send commands to
stdout, read responses from
stdin, and listen for asychronous events (e.g. keyboard and mouse events)
on a named pipe.
I may never use NanoVG-REPL for serious work, but I consider the experiment a success. I'd like to try wrapping a more modern 2D graphics library this way. After I wrote NanoVG-REPL, I found out about GTK-server, which uses the same approach to wrap the GTK GUI library, so I'm not the only one thinking along these lines.