I managed to get my hands on an Insignia Infocast 8 used at a bargain price on eBay. It’s an 8″ touchscreen device that is a clone of the Chumby. They’re designed to be hackable, so you can SSH into it as a feature. The apps are written in Flash, and I managed to get my first one running yesterday. Of course I’m using Linux tools only, but found that Haxe and Geany do a great job. I’ll roll the code and the steps I took into the post after the jump.
After completing my first iteration of Conway’s Game of Life I was unhappy with the performance. After a bit of testing I discovered that the real bottleneck wasn’t in my algorithm, but in the overhead associated with the pygame module that was taking care of the graphics.
I finally got around to programming Conway’s Game of Life. I’ve long wanted to give this a try but just today decided to take some time to myself and actually do it. I chose Python, a language I’ve worked with quite a bit but one I’ve never used for GUI programming. I spent the majority of my time trying to figure out how to display the Life grid, and decided to use a package called pygame, which I enjoy quite a bit!
About the code:
The game itself was actually pretty easy to code. I decided to make a multidimensional array as a lookup table. The first dimension is indexed by whether the current cell is dead (0) or alive (1). The second dimension is indexed by the sum of the living cells around the test cell. The return value is status of the test cell after the rules are applied for the next generation. The rest is just iterating through the various buffer arrays and then writing to the display.
The number of cells, cell size, gap between cells, delay between generations, and percent of live cells at genesis are all configurable. The game checks for stagnation at the end of evolution and will change the window title to show how many it took to reach equilibrium.
The pygame package turned out to be very easy to work with. I has an event handler that takes care of the delay time between generations. Take a look at it if you are ever working on a game!
I’d love to hear your thoughts about my code. Check it out and then leave a comment or send me a tweet!