Daniel Petersen's Blog

Documenting my struggle to make a videogame, amongst other nonsense


Home Projects

Conway's Game of Life

Web based verison here

I’ve made two versions of Conway’s Game of Life. The first version is C++ with SDL (pictured above), and the second version is HTML + JS linked to above. The code for the HTML + JS version can be found here.

I made the HTML + JS version because I wanted Conway’s Game of Life to be my Laptop’s screensaver, and apparently xscreensaver will happily use a webpage.

The C++ version was one of first projects that I made, but it also might be my favorite. I remember my father got us a computer when I was very young, and one of the programs that came bundled on the machine was Conway’s Game of Life. It had two colors you could spawn, I think green and red, and I really liked placing the colors down and speeding the program up to see which color “won” (really just which color outlasted the other).

I wanted to replicate that with the version I was making, and I did so by allowing you to place 8 or 9 cell colors on the board. To make things more interesting, I made it so the color of any new cell born was the average of its three parent colors. This creates something akin to natural selection, it’s pretty fun to watch.

I made my own rudimentary GUI system for the program. There’s an option to speed up/slow the game down. You can also choose to place predefined interesting patterns that people have found such as the Gosper Glider Gun. You can also invert all the colors on the board, toggle the grid on / off, modify the rules, and well yeah, there’s a lot of options.

I revisited the project some months after completing it in order to implement an infinite grid. It’s really just a series of connected 800×600 grids which appear dynamically depending on where they’re needed. So it starts off with one grid, and if you click in an area where no grid exists, a new one will pop into the appropriate position. Grids will also appear if you have an alive cell on the edge of one of your grids. The memory gets freed up when a grid is no longer needed.


Copyright © - Daniel J. Petersen