2016
01.17

Poly polypolgon

So, creating a vector animation for talks, once you have a pdf with each page being a frame of the animation is not hard, see here for details.

The question remain, how do we generate such a pdf to begin with? One way is by using a drawing program. Ipe is a good candidate, but creating such figures can be tedious, to put it mildly. In some cases (and you might want to sit before reading the rest of this sentence) there is really no better alternative to… doing some real programming!

Luckily, there is a light graphics library, specifically Cairo, that is happy to output directly to pdf (or svg) files, generating true vector drawings – which are both small, and of higher quality than the “standard” bitmap output (yuck).

Of course, you might want to have an interactive program, with a window and stuff, and output to pdf/svg only when you are happy with the results. Cairo is happy to let you do that – the same drawing code can be used to output to the screen, or to a pdf (or svg). Once you have a pdf, you can easily convert the figure to ipe, and edit the figure directly (using pdftoipe).

As a demonstration of the above, here is the source code of an interactive program I wrote (that I used to generate the above figure). Its a C++ program for linux, using gtk, cairo, and CGAL (because life is too short to implement 2d point class yet again). If this sounds like many libraries one needs, on Debian/Ubiuntu this just requires installing the relevant packages (you would also need the pkg-config package — a nice programming tool). The program is self explanatory as far as what keys do.

And a final comment — to force cairo to output the current image to a new page in the pdf file, one need to use cairo_show_page.

Comments are closed.