Hysen Labs
Open-source project
ethomson/github4life avatar
ethomson

github4life

Using your GitHub Contribution Graph as a four-color Game of Life.

100 stars19 forksJavaScriptMIT
01
DEEP OPEN-SOURCE ANALYSIS

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.

02
DEEP OPEN-SOURCE ANALYSIS

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.

03
DEEP OPEN-SOURCE ANALYSIS

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.

04
DEEP OPEN-SOURCE ANALYSIS

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.

05
DEEP OPEN-SOURCE ANALYSIS

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.

06
DEEP OPEN-SOURCE ANALYSIS

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.

08
DEEP OPEN-SOURCE ANALYSIS

Official sources

09
Community notes

Community notes