How should a drawing program render?

John Hunter jdhunter at ace.bsd.uchicago.edu
Wed Sep 15 13:17:24 CEST 2004


>>>>> "Leif" == Leif K-Brooks <eurleif at ecritters.biz> writes:

    Leif> I'm considering writing a fairly basic vector drawing
    Leif> program using PyGTK. What's the best way to render it? What
    Leif> I'm thinking of is having everything render on a PIL image,
    Leif> then display that in the GTK window or save it depending on
    Leif> what's being done. Is that the best strategy? Will it be
    Leif> fast enough?  --


The first obvious candidate of course is to use a gtk.Drawable,
ie native gtk drawing.

That is what I started with matplotlib and it does a respectable job,
and it is fast.  It does not support antialiased drawing, which is a
limitation, and is not natively vector based, which is another.  

The larger problem with this approach is your application may one day
grow beyond your initial plans and you may want to port it to other
GUIs.  At that point, it's easier to port if you used some GUI
independent buffer to draw into and simply blit the contents of that
buffer to your GUI canvas of choice.

matplotlib, inspired by the plotting package chaco, uses the antigrain
library (http://antigrain.com) for drawing to a buffer, and then this
buffer is transferred to the GUI canvas (wx, pygtk, fltk and tk
currently).  antigrain is a very powerful, modular, vector based c++
library for doing antialiased drawing, and supports most things you
would want in a 2d library: paths, even-odd filling, arbitrary
clipping, antialiasing, alpha, gamma and so on.  You can use
enthought's chaco package and matplotlib as examples if you want to go
this route - each takes a different approach to wrapping and using
antigrain.  matplotlib contains code to blit the antigrain buffer to
pygtk, and the other GUIs mentioned above.

Since antigrain is already vector based, it is a natural candidate to
support a vector graphics app, unlike the native gtk drawing model.
Also, you should look at wxart2d (http://wxart2d.sf.net), which uses
antigrain to develop a vector library for wx, much like what you are
proposing for gtk.

As for performance, on a modern pentium computer, I can draw and blit
to gtk about 50 frames per second using the gtk/agg matplotlib backend
for simple images.  For more complex graphics, eg if image resizing
and interpolation is involved, the rate is about 10fps for typical
window sizes.  YMMV.

Of course, if you are allergic to C++, this may not be your best
option.  

JDH



More information about the Python-list mailing list