# Chaotic Particles using OpenCL

Posted on in Strange Attractors, Tech Notes

First, a big thank you to Memo Akten for writing an OpenCL C++ wrapper for OpenFrameworks and providing a great million particle demo (see http://vimeo.com/7332496). You are looking at one of my modifications, where the mouse position becomes input to two parameters of a two dimensional chaotic dynamical system (a strange attractor). A serendipitous coding accident created some really intriguing effects.

I like to visualize strange attractors in real time, and OpenCL is a promising technology to take this to the next level, as it can utilize all processing cores available on a system, be they GPU, CPU, or a combination. As long as the algorithm can be made massively parallel. This is not too hard with the equations I’m working with… they are simple iterated functions – pop in an x and y coordinate and get a new x and y coordinate. Repeat this many times, and the strange attractor appears. Although most people are used to having one thread perform this iteration, there’s really no reason that a million threads can be performing it. As long as the starting positions of the particles are randomized, you’ll still get the strange attractor.

Almost. There’s an interesting numerical side-effect… when the attractor goes into a less chaotic orbit, and then comes back out to a more chaotic orbit, everything is “sparkly”; i.e. the points in the attractor are not well distributed. Because they all started from a fixed set of points (not theoretically but in practice, as they are floats), they zip around to a fixed set of points in the attractor. Or something like that.

Anyway, I attempted to overcome that with some added randomness. In the process, I have come across two really cool “accidents”, of which this is one (I love accidents in code). Basically, I’m adding a bit of random jitter to each particle. But the random value range I first tried was big enough to create this amazing motion. WOW.

Memo’s demo on Vimeo

Memo’s post on his website with more info