I while ago, I stumbled upon a famous paper of Alan Turing called The chemical basis of morphogenesis. It is fascinating to see the idea of using diffusion – reaction equations to simulate the creation of animal patterns. In his paper, he describes his idea to use two non-uniform distributed chemicals that react with each other and diffuse in high- and low concentrations, forming all sorts of patterns which look similar to patterns you see in nature. There are a few version now, known as the 2 component diffusion reaction system. I used a slightly different version, known as the Gray-Scott model, written as

$$\begin{eqnarray} \frac{\delta u}{\delta t} &=& D_u \nabla^2 u – uv^2 + F(1-u) \\ \frac{\delta v}{\delta t} &=& D_v \nabla^2 v + uv^2 – (F+k)v \end{eqnarray}$$

using circular boundary conditions. In the system of equations, u and v are the chemical components, F and k are denoted as the feed and kill rate respectively.

The demo simulation has been programmed in Javascript, using Html5 Canvas to render the output. To get the best performance, an off-screen pixel buffer is created for every frame and raw pixels are set directly. To speed up the animation, each frame shows the result after 50 time steps.

Diffusion-reaction for different values of F and k. Click in the simulation to change the patterns.

The first pattern is remarkably similar to the pattern of a leopard, the second pattern has similarities of the skin of a mackerel.

When changing the kill and feed values, different patterns can be created. The possibilities are almost endless.

In a future blog post, I will show another way of solving the system of equations, by applying parallel computing, using the power of the GPU only.