github4life
Using your GitHub Contribution Graph as a four-color Game of Life.
github4life: turning your contribution graph into a Game of Life GIF
A Node.js app that reads a GitHub contribution graph and runs it as a four-color variant of Conway's Game of Life, delivered as an animated GIF.
What the app does
The application takes a user's GitHub Contribution Graph as input for a four-color variant of Conway's Game of Life. The game is delivered as an animated GIF, with each generation sent as a frame. The game plays forever, and the README notes there is no end to the animation, just frames until you close the window or the browser runs out of RAM.
Why four colors
Conway's Game of Life is described as cellular automata that is simple to reason about and program but leads to interesting and sometimes surprising results. The original supports two states, alive or not, but multi-color variants exist. A four-color variant suits the GitHub Contribution Graph because the graph has four levels of intensity of contributions on given days, so the graph can serve as the starting condition.
Modified decay rules
The README explains why the rules are modified. Quad Life uses the same algorithm for determining cell state as the original Game of Life, which is imperfect when a contribution graph has a lot of work. With many filled blocks there is rampant overpopulation, and the next generation is basically an empty board after a mass die-off. Instead of a cell dying immediately, it decays, so a cell at intensity 4 becomes a cell at intensity 3, which produces a more visually interesting game with a heavily loaded graph.
Serving an endless GIF
Animated GIFs normally run through frames to a final frame, but the format does not require prefixing the number of frames. If you keep sending frames, most browsers just render them forever. So the app sets a delay between frames of zero and renders and sends a frame every second. Some sites like GitHub cache images through a service called camo, and you cannot cache a GIF that never ends, so the app has a special camo mode that renders a finite GIF quickly, since camo also has a 4 second timeout.
The libraries underneath
Two npm libraries handle the work. The contributions library parses the GitHub Contribution Graph by screen-scraping GitHub output and parsing the DOM, which the README jokes is a little better than hitting it with regular expressions. The dat-life library plays the Game of Life, including two and four color variants and the decay mode used here. Neither produces any data itself, so the gifencoder package creates the GIFs sent to browsers.
Community notes