Sunday, December 13, 2009

Diffusion limited aggregation

Click the image on the left to view the canvas demo. This is an example of diffusion limited aggregation - a natural process where randomly moving particles stick together, to form clusters. A good example is crystals. An initial seed is fixed in place, then particles are randomly moved around until they hit part of the main cluster, where they stick. This leads to a bigger cluster and feeds back on itself, producing a stochastic fractal (Stochastic means a random process) Code comments: I wrote this after looking at the C code for "diffuse.c" from The Computational Beauty of Nature (see books). An optimisation I copied from there is to constrain the particles to within 10 pixels either side of the cluster, to stop particles wandering off where they would never hit anything. This shouldn't have too much effect on the resulting graphics but is much faster (especially at the start)

3 comments:

  1. Very cool. I built a DLA simulation using Processing a few years back. My code is available here:

    http://stungeye.com/processing/1007/

    ReplyDelete
  2. Hey Wally - I like the look of your version over mine.

    1. Drawing the unattached random particles makes it much more clear what is happening

    2. Your version appears more round and natural looking while mine has artifacts due to being constrained in a box. It looks like you are constraining the random particles in a radius, giving a more circular appearance.

    ReplyDelete
  3. Hi Dave.

    The roundness took some tweaking. Here are three techniques I employed in an attempt to make the crystal look more natural:

    As new particles are tossed into the system they appear in a "donut" around the crystal. The inner radius of this "donut" increases as the crystal grows.

    Each free particle is also weakly gravitating towards the centre of the screen. The longer a free particle has been floating about the strong the pull.

    Lastly, the particles only "stick" diagonally %25 of the time, whereas horizontal/vertical touches always crystallize.

    ReplyDelete