Conway Cubes

- 3 mins read

The very first time I paired during my Recurse batch, we were asked to implement Conway’s Game of Life, which was relatively straightforward to do and looked rather spiffy on execution (we just utilized Python’s print function on a sufficiently large enough board to make it “feel” animated). It was the first time I’ve ever had to implement the Game of Life and it was quite fun to see the animations go off and do their own thing out of relatively simple rules. We experimented by seeding random maps based on a probabilistic cutoff at the beginning of every round, ranging from a nearly fully dead map to fully live, and altogether it was fairly fun to do and a great icebreaker for meeting the other Recursers in the batch.

Much, much later during the batch, I recalled one of the earliest exercises I did in Advent of Code that I liked, that I often compare to another puzzle from the same year: 2020, Days 17 and 20. One of these is conceptually difficult to grasp (there’s a whole bit about doing something in dimensions higher than 3) but relatively easy to do (17) and the other is conceptually easy to grasp but not really that easy to do (20). Revisiting day 17 made me realize that it’s just Conway’s Game of Life again, but in 3D! What did it look like, I wondered, if I animated this? Is it as pretty as the 2d version? So I added it on the the wishlist of fun animations to put together. (I have a lot of these, mostly stemming out of curiosity and a desire to learn Javascript better.)

As it turns out, it’s relatively easy to do in p5.js in WebGL mode! Maybe the only real hurdle is adapting to the origin 0, 0, 0 being centered on the canvas rather than the upper left as it is in 2D mode, but otherwise fairly straightforward. Most of the time spent was finding the settings for adjusting colors and lighting. I made the executive decision to constrain the cube size rather than expand to the entire screen, as it turns out making it that large makes it very hard to view what is happening: in 3D the AoC rules are surprisingly busy/stable. Part of it may have to do with the edges of the cube being arbitrarily constrained by number of existing adjacent cubes (since you have to do a check of 26, rather than 8, adjacent areas), which encourages liveness, but not entirely sure. Seeding only 5% of the board gets you to lively animation, as evidenced by the animation.

Quite coincidentally, this animation turns out to be the very last thing I do during my the Fall 2025 batch (since the batch ends today), so not a bad way to open and close what had been a really wonderful experience at Recurse.

Feel free to watch the animation here.