Colorizing sdl2-life

After letting the life server I wrote about last month run for a bit I decided that all white cells are a bit boring and I started exploring ways to add some color to it. First step was to keep track of the age of the cells, and I decided that new cells should inherit the age of the cells that created it in the hope that it would be more visually snazzy. I started with the color code from the wasm mazes project .

sdl2-life running

I didn’t like how it looked, so I stumbled around looking for something better. And I found this wonderful post by Ben Southgate on creating color gradients using python. After a bit of trial and error, and some really ugly go math, I ended up with 3 different algorithms for coloring the cells. Here is what a Bezier gradient from red, to green, to yellow to white looks like:

sdl2-life running

Run it with a cmdline like this:

sdl2-life -color -colors #ff0000,#00ff00,#ffff00,#ffffff -gradient 2

The color codes are hex triplets. The type 0 linear gradient uses the first and last in the list. Type 1 is a polylinear gradient that uses pairs of colors to join gradients together, and type 2 is a Bezier gradient that uses a curve for a nicer transition between colors. You can add as many colors as you want. The # is optional if you separate with commas, and the commas are optional if you include the #.

You can also pass -age 255 to change how much time the gradient covers, the default is 255 ticks.

Of course this all works with the server option, here’s what it looks like when I pipe the logs from my webserver to it: