Diffusion-Limited Aggregation

Diffusion-Limited Aggregation (DLA) is one of the first algorithms I ever implemented following Daniel Shiffman's 34th Coding Challenge. It's one of the first digital morphogenesis algorithm that became well known and toyed with by geeky fractal digital artists in the 90's as computers then had just enough power to start simulating Brownian Motion.

Though DLA is characteristic to chemistry, describing the diffusion and aggregation of zinc ions (Zn2+) onto electrodes in an electrolytic solution, it is also the basis of the Brownian Tree structure, a pattern omnipresent in nature, formed by clusters of randomly moving particles aggregating in one place. You've probably seen it before, in the way that lightning strikes tear through the sky, or in the ways that some corals grow in the reefs.

the diffusion-limited aggregation algorithm

A key element to this algorithm is the random walker, or walker for short, which, aside from being the word used to designate zombies in a terrible tv show adapted from a great comic is also the name given to randomly moving particles.

The system is initiated with Step 1 : Setup Walkers & Aggregation in a setup function. Step 2 : Random Walk and Step 3 : Stick are then repeated at every frame of the simulation (typically in a draw function). Here is an example where you can see the random walkers avidely aggregating towards the center in their lust for blood.

Waiting for the aggregation to form can be pretty uneventful sometimes. In the 90s it could take entire days for computers to generate large Brownian Trees, but today, using the right optimisations it's possible to get the intricate patterns formed by thousands if not millions of particles in real-time on an average computer. I sometimes use a custom Quad Tree data structure for this purpose exactly, though recently I have become very passionate about GPU coding as a means to parallelize large amounts of similar operations. In fact, all the code poem simulations involving particles use a GPU accelerated particle system made from scratch. Though if you want to avoid being as environmentally unconcerned as a bitcoin miner, a massive optimisation and power saver is to add a tiny towards aggregation force. To slightly encourage the particles to move towards the aggregation center. By choosing a low force coefficient you shouldn't loose to much of the original pattern.

That's it for today ! If at some point I finally crack GPU QuadTrees I'll make sure to upload a version with a million particles as the patterns start to get really interesting at that point. Ttyl :)

Kaspar Ravel ~ for the Institute of Something
If this resonated with you and you'd like us to work together, let's talk ! I'm as much of a performance artist than a teacher / researcher in the new media arts, so feel free to shoot me anything at kaspar.ravel @ gmail dot com.

This code was developped in javascript using p5.js, three.js and <3.
All is licensed as CC BY-SA 4.0 (Attribution-ShareAlike) meaning you are allowed to copy, share, remix, build upon, as long as you give appropriate credit and reshare with the same license.