Saturday, March 11, 2006

Well, it's not really pretty, but I managed to convert my artificial life program from the MS Windows platform to the Mac. Fortunately, the program had originally been written in C++ and used OpenGL for the graphics, so it was mostly portable. The only part I had to change was the initialization of the graphics display window. On the MS Windows enviroment, I was doing a bunch of messy things on startup dealing with graphics contexts and such. For the Mac, I switched over to using GLUT, which greatly simplified the initial graphics startup, and as a side effect the code is now pretty much completely portable for other platforms that also use GLUT. There really isn't any Mac-specific code.

This porting was mainly done as a learning exercise so I could gain some familiarity with the Xcode development environment on the Mac.

If you have a Mac running OS X and are interested in trying it out, you can download the binary here.

After downloading the disk image, open it and drag the "Soup" folder to whereever you'd like. Then run the "Life" program located in this Soup folder. Once the program is running you can press the "up" arrow key to switch to fullscreen, or the "down" arrow key to return to window mode. You can also resize the window by dragging the lower right-hand corner (like most Mac windows). Pressing "ESC" will exit the program. (As a side note, I'm not sure whether it's the Mac's compiler optimizations or what, but the program runs dramatically faster on my 1.5 Ghz Powerbook than on my 2.5 Ghz MS Windows-based Dell which I use at work.)

I had been goofing around with making an installable package with the PackageMaker program that Apple provides, however it seemed like overkill for this simple program. It seems easier to just let someone drag a folder whereever they want rather than go through a whole install process. I still need to figure out how to make the Life program have a different icon than an executable shell and also get rid of the console window that pops up when the program is run.

If you are interested in the source code for this program, feel free to contact me. I should note, however, that it is not at all pretty. It was written over 5 years ago when I was just tinkering with some ideas for artificial life algorithms. It was mainly a stream-of-consciousness thing done over the course of a day or two, and the code never got cleaned up after that initial burst of inspiration. As such, expect to see lots of examples of bad coding. At some point I might actually clean the code up and make it more presentable, but there are just too many other things I'd rather spend my time on.