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.

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 a blog 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. Then I worked with C because that's the language I know best. At that time, the program generated images using the gifsave89 library.

Because I wasn't satisfied with generating GIFs, I switched to SDL for displaying the generated images and adapted the rest of the program to C++. I don't have a lot of experience with C++ and I mostly learn as I go, so the code is really C with some C++ features that were useful to me. The source code is on GitHub.

Below is an animation generated with an older version.