Various Python Experiments
Every so often I decide to write simple test programs in Python just for the fun of it. Here are a few that I had written over in the past. Please note, because these were originally just simple experiments the source code could be a little messy and poorly optimized in most of them. Also note, these are not meant to be all that impressive.
All of the programs require Python and PIL (The Python Imaging Library.)
Simple Recursive Maze Generator
This is just a simple maze generator that uses a recursive function. It creates a near-infinite number of random mazes.
Source: maze.py
Rectangle Packing
I wanted to figure out a simple and effective way of packing rectangle images in an OpenGL texture — which is useful for hardware accelerated 2D graphics. The solution I came up with simply subdivides the availible free space and packs the rectangles from largest to smallest. It may not produce the best packing results and there are quite a few wasted cycles in this implimentation, but, for being as simple as it is, it produces fairly reasonable results rather quickly.
Source: rect_packing.py
Simple Error Diffused Dithering
Just simple error diffusion based image dithering. The above image is showing four color dithering.
Source: dither_test.py
Random Forest Path
I decided to try to see if I could easily produce a visual effect resembling erosion patterns in a forest area. This was part of some preliminary work in trying to write a game that randomly generates a completely different world each time it’s played. The results were very satisfying considering how simple the solution is. Essentially it’s just squiggly lines of varying thickness with some textureing applied to it.
Source: forest_path.py
Image Outlining
Originally I wanted to see if I could have interesting features of an image identified and later used in some sort of image recoginition system. Hilighting sharp edges brought out too many points to practically be used for comparing spacial relationships and proportions, but it did produce some nice results for drawing outlines on an image.
I wanted to test it on a picture of a person, so I found the above image online. It is actually a composit of 32 american male faces averaged together. I hope the creators of the website he’s from does’t mind.
Source: img_outline.py
Tags: experiments, python






November 12th, 2008 at 6:41 pm
Pretty cool stuff, I don’t understand everything that you were describing but I can see how these things especially the mapping tools would come into play with making a game.