Stable Fluids

Pac-Person

Before I talk fluids, I first want to catch up on my Pac-Man 256 clone progress. At first I tried to look into ways to procedurally generate the maze the player navigates using traditional maze generating algorithms. After playing around with a modified breadth-first search approach (the results of which can be seen below), I realized the results looked a little too random and were a far cry from the levels found in the game.

Procedural Maze Attempt

Upon playing the original game a few more times I started to notice a few consistent things about the board. This included things like the starting layout always being the same:

Pac-Man 256 Start Zone

and a seam appearing every so often:

Pac-Man 256 Seam

This suggested that the endless levels were more likely comprised of premade sections that are stitched together at predictable seams. Because of this, I switched my approach from purely random generation to stitching together of premade sections. So far, I’ve managed to put together a simple editor for designing the chunks to be stitched together. For example, a Mario of sorts:

Mario Level

Next up is exporting the designed sections and then developing a system for continuously loading them into the game.

Stable Fluids

Now on to the namesake of this post. I attended a Toronto SIGGRAPH chapter talk last night hosted by the illustrious Jos Stam, where he talked about the history his work on real-time fluid solvers and plugged his new book, The Art of Fluid Animation. The work was pretty groundbreaking at the time and ended up winning him an Oscar in 2008 for its integration into Maya’s Fluid Effects system. Much of the background on fluid mechanics was a bit lost on me, but what caught my attention was his mention of the original paper’s source code being simple (100 lines of C) and freely available (albeit patented). Today, I found myself a copy and quickly ported it over to JavaScript, using a 2D canvas to do the drawing. I kept it as true to the original as possible and put up a demo you can play with here. It’s simplicity means that it shouldn’t be too hard to implement in GLSL, so I intend to give that a shot soon.

Stable Fluids Demo

Updated: