I’ve always been fascinated by Conway’s Game of Life and other cellular automata. It’s amazing how a simple set of rules and primitives can give rise to enormous complexity and even emergent “life”!

For the uninitiated, Conway’s Game of Life consists of a grid of cells and a set of rules. A cell is either dead or alive and its state changes based on the state of its neighbouring cells. Quoting Wikipedia:

1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.

2. Any live cell with two or three live neighbours lives on to the next generation.

3. Any live cell with more than three live neighbours dies, as if by overcrowding.

4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

Applying these rules repeatedly to a randomly populated grid can lead to an animated frenzy of patterns. The simplest patterns are just static “still lifes”, like a 2 by 2 block of live cells, that remain in the same state after the rules are applied. Other patterns oscillate between two states forever. Wikipedia goes into much more detail, so I encourage you to read the page for more information.

One of the most interesting patterns, however, is the “glider”. A simple 4 by 4 pattern that actually moves across the grid in a diagonal path. These gliders are actually quite common on a randomly populated grid but they can be hard to spot as they flit in and out of existence on a busy grid.

I’ve written a bit of JavaScript to help remedy that. The code uses brute force to scan the grid for the patterns that identify a glider. It then renders the gliders in a different color and keeps track of statistics that reveal just how prevalent gliders are. Press the start button below to see it in action.

View the source code in my “Gliders of Life” project on GitHub.

Being able to detect gliders on a grid allows for some interesting applications. For instance, you could count the number of gliders and use that count as a measure of “interesting” activity in a grid. You could also try to determine the optimal conditions for glider generation.