Learning Python by building image-pooping Markov chains

Fri Dec 19 2008 23:41:05 GMT-0800 (Pacific Standard Time)

tags: python programming markov

In my ongoing attempt to learn yet another utilitarian programming language, I have decided to pick up some Python. I'm only still scratching the surface (for example I haven't even touched python regular expressions yet, nor object persistence/marshalling), but I've managed to make a few toys. I often learn best by just diving in and doing, and I've come to enjoy stumbling through toy projects when learning a new language.

So I thought it would be interesting to see what kind of images I could create with a self-modifying, mutative Markov chain. While the results below aren't yet self-modifying, they're somewhat entertaining eye-candy that's probably been done hundreds of times before.

image image image image image image image image image image image image image image image image image image image image image image

I'm using the Python Imaging Lirbary (PIL) to create/paint the images. Sure, it's pretty well documented and intuitive, but doesn't immediatly support drawing with alpha transparency, which is a real bummer. There is at least one other drawing toolkit that does alpha, and one that does that with opengl. It would be nice to render these in realtime, but the current incantation seems to take about a second to do about 54k 2d polygons, which isn't exactly fast. I'm also not yet sure how much of that time is spent in python versus actual Tk rendering.

I'm now mostly interested in switching drawing toolkits to support alpha, doing marshalling to save/restore interesting chains, and coming up with interesting strategies of self-modification. The current models are very linear, and it might be nice to have a little abstraction that allows nonlinear curving to happen more seamlessly.

I'll probably share the code after I continue to learn from my mistakes and make things more better.