A while back I said I’d do something with the Kuramoto Model, and, well, it turned out to be easy, fun, and rewarding. My idea – not original – was to put lots of oscillators in a grid, each one coupled to the ones above, below, left and right of it, and see how the grid changes over time. This is now online, and the source is in my github as ever. A series of screenshots:

So the first shot is pure noise – the random initial conditions. Each oscillator has an angle, theta, representing the phase of the oscillator, represented as hue. I was able to recycle my code that used tinycolor.js from Mandyn, to make it easy to do this. Each oscillator also has a natural frequency – in this experiment, the natural frequency decreases down the grid, reaching zero at the bottom.

Early on, the oscillators start to synchronize, aligning their phase angles, leading to a nice smooth grid. But why not one bit smooth region of one colour? It turns out there are other ways to reach stability. One way is to go round in a circle with gradually increasing phase angles, so each oscillator is in contact with oscillators ahead of it and behind it – so on average, synchronized with it. Thus the oscillators can oscillate happily at their natural frequency, without the synchronization effects effecting them. So what you see is a region where the colours go round in a circle – maybe with an unhappy little dot in the middle.

Leave the system going a little longer, and stripes start to form. This was an accidental discovery – I’d aimed to vary the natural frequencies to see what the system looked like at different natural frequencies, but it turns out that if you have a gradient of natural frequencies, then you get stripes. With some ingenuity you can get circular stripes, or stripes of varying width, or whatever. However, the stripes aren’t “pure”. There are all of those places where the colours go round in circles, and they continue to do that even as stripes form, disrupting the stripes.

One effect of the synchronization effects smoothing things out – by taking a local average (not quite an average in this case) – is to make the system tolerant to various forms of noise. The noisy initial conditions mostly smooth out, leaving just enough in terms of colours going in circles to make things interesting. You can add noise to each oscillator at runtime, and the patterns that form can survive that. Also, you can add a random factor to the natural frequencies of each oscillator, and the patterns get less smooth, but they’re still recognisable as the same basic pattern. The nice idea I can take away from this is the trick the system uses to get an “average” of angles – this might be handy later on, not just with angles as such, but also with complex numbers.

A slight technical note: as there are lots of ways to set up the parameters for the model, I decided that this was a good time to use eval. It’s almost never a good time to use eval, but here, it lets you set up your own functions. There are lots of pretty patterns to be had by setting things up the right way.