Stream drawing with Pivi
Motivation
While working in the university I supervised many student works. Most of them involved some form of programming and visualizing the results. I noticed that nearly all of the students put a lot of effort into creating an environment in which they can visualize their results. Some of them use some fancy tools others start with the bare minimum with varying results from crappy unusable tools to surprisingly beautiful solutions.
And in every work I had at least some of the following issues:
- missing export mechanism
- unusable controls
- cumbersome dependencies
- not portable
- overly complex design hiding the important work
- etc.
But the worst issue is, that students forget the actual task an put much more time into the visualization rather than into the actual problem solving. As I see it, students start creating the visualization environment and get excited with extending it etc. that they neglect the actual task.
The Pivi Approach
A colleague of me and I create a small and simple language that should solve most of the problems. It is a stream based drawing language that allows for an easy dependency free 1 development.
Drawing in Pivi is fairly simple. You create a stream of commands and pipe it into Pivi which does all the drawing, conversion to animations etc. Pivi itself will need some dependencies, but it is possible to implement different Pivi clients making it easier to be portable.
A Pivi stream could look like this:
line (10 10) (200 200) :stroke red
line (10 200) (200 10) :stroke blue
circle (40 40) 10 :fill yellow
You can pass this stream into Pivi and get an image out of it. This works in every language, e.g. in Python it could look like this:
print("line (10 10) (200 200) :stroke red")
print("line (10 200) (200 10) :stroke blue")
print("circle (40 40) 10 :fill yellow")
And then you call python prog-above.py | pivi
and get an image as a SVG. For animations you simply add a line newframe
and start the next frame. The basic language is small and thus it is simple to write a different Pivi client on your system.
Check out the Pivi Clojure client at Github
Further Development
Pivi itself is rather small and has only a handful of features, but due to its stream based nature it is easy to write middlewares that add extra features like keyframe support or simple chart tools. A middleware takes a stream of commands in an extended format and transforms it into Pivi syntax (or a simpler middleware format). A possible middleware could transform CSV datasets into graphs drawn with Pivi like this:
cat graph.csv | csv2pivi --data "volume" --over "time" | pivi
Where --data
could select the column volume
and --over
defines the abscissa.
You will need a Pivi translation unit with it's dependencies for drawing. ↩