There are many visual patterns that occur naturally: zebra stripes, leopard spots, tribal tattoos... Ah well, maybe not the last one. Anyway, it turns out that some of these patterns can be described mathematically and computer-simulated. Starting with a grid of pixels of random values, and applying a simple set of rules over and over again, you see unexpected patterns emerge. Maybe you know Conway's game of life, that's the same kind of idea. Right now we're interested in Turing patterns, or reaction-diffusion patterns, which have been first described by Alan Turing. We owe him a lot, don't we?

Jonathan McCabe published an algorithm to generate "Cyclic Symmetric Multi-Scale Turing Patterns". Multi-scale because the patterns exist and evolve at different levels and at different timesteps (e.g. small wobbly mazes wobbling along with big wobbly mazes), and cyclic-symmetric because there's some circular averaging involved in the process, which gives a kind of mandala feeling to the generated pictures.

His published pictures and the videos that can be created with his algorithm (see below) are amazing. Think of a Windows
Media Player visualization who quit her job and started doing LSD and
listening to aggrotech. McCabe was nice enough to give lots of
additional details about his algorithm to Jason Rampe, who published
them in this blog post.
Originally, I became aware of McCabe's work thanks to that post
by Frederik Vanhoutte.

Some developers have already put their implementation online, see for instance this and that. I wanted to write my own so I can really understand the algorithm and play with it to discover different kinds of patterns (hopefully). At first I tried in Python, because I'm learning it so I thought it would be a good exercise. It was, but the generation was also really, really slow. Now I'm working with C because it's my favorite language and it's much faster for this application.

The source code is on GitHub. It uses the gifsave89 library to generate gifs, static or animated. I just took that one because the API is really simple, but I might pick another library later. The documentation is generated with Doxygen. To understand the algorithm, **everything** that you need to know is explained in the above mentioned blog post.

As of today, the program runs and it's quite fast, so I got that going for me, which is nice. Generated animated gifs can get huge, though. And it works only with square images. See the last log about the current limitations/unresolved bugs. Here's a video that I generated.