views:

2730

answers:

5

I woud like to create a cross-platform drawing program. The one requirement for writing my app is that I have pixel level precision over the canvas. For instance, I want to write my own line drawing algorithm rather than rely on someone elses. I do not want any form of anti-aliasing (again, pixel level control is required.) I would like the users interactions on the screen to be quick and responsive (pending my ability to write fast algorithms.)

Ideally, I would like to write this in Python, or perhaps Java as a second choice. The ability to easily make the final app cross-platform is a must. I will submit to different API's on different OS'es if necessary as long as I can write an abstraction layer around them. Any ideas?

addendum: I need the ability to draw on-screen. Drawing out to a file I've got figured out.

A: 

QT's Canvas an QPainter are very good for this job if you'd like to use C++. and it is cross platform.

There is a python binding for QT but I've never used it.

As for Java, using SWT, pixel level manipulation of a canvas is somewhat difficult and slow so I would not recommend it. On the other hand Swing's Canvas is pretty good and responsive. I've never used the AWT option but you probably don't want to go there.

shoosh
+1  A: 

The Pyglet library for Python might suit your needs. It lets you use OpenGL, a cross-platform graphics API. You can disable anti-aliasing and capture regions of the screen to a buffer or a file. In addition, you can use its event handling, resource loading, and image manipulation systems. You can probably also tie it into PIL (Python Image Library), and definitely Cairo, a popular cross-platform vector graphics library.

I mention Pyglet instead of pure PyOpenGL because Pyglet handles a lot of ugly OpenGL stuff transparently with no effort on your part.

A friend and I are currently working on a drawing program using Pyglet. There are a few quirks - for example, OpenGL is always double buffered on OS X, so we have to draw everything twice, once for the current frame and again for the other frame, since they are flipped whenever the display refreshes. You can look at our current progress in this subversion repository. (Splatterboard.py in trunk is the file you'll want to run.) If you're not up on using svn, I would be happy to email you a .zip of the latest source. Feel free to steal code if you look into it.

Steve Johnson
+1  A: 

I just this week put together some slides and demo code for doing 2d graphics using opengl from python using the library pyglet. You can see my stuff here: http://www.tartley.com/?p=378

It is very fast (relatively speaking, for python) I have managed to get around 1,000 independantly positioned and oriented objects moving around the screen, each with about 50 vertices.

It is very portable, all the code I have written in this environment works on windows and linux and mac (and even obscure environments like pypy) without me ever having to think about it.

Tartley
A: 

I would recommend wxPython

It's beautifully cross platform and you can get per pixel control and if you change your mind about that you can use it with libraries such as pyglet or agg.

You can find some useful examples for just what you are trying to do in the docs and demos download.

Toni Ruža
+1  A: 

If language choice is open, a Flash file created with Haxe might have a place. Haxe is free, and a full, dynamic programming language. Then there's the related Neko, a virtual machine (like Java's, Ruby's, Parrot...) to run on Mac, Windows and Linux. Being in some ways a new improved form of Flash, naturally it can draw stuff. http://haxe.org/

DarenW