Awesome Open Source
Awesome Open Source


Diffusion-limited aggregation, fast. Diffusion-limited as f*ck.


  • 2D or 3D diffusion-limited aggregation
  • Super fast? 35 seconds to compute one million points on a single core.


  • boost (used for its spatial index)


git clone
cd dlaf
./dlaf > output.csv

Output Format

The parent_id tells you which particle was joined to. It is -1 for initial seed positions. When 2D is used, Z will be zero for all points.

# columns are: id, parent_id, x, y, z
$ head output.csv

Hooks & Parameters

The code implements a standard diffusion-limited aggregation algorithm. But there are several parameters and code hooks that let you tweak its behavior.

The following parameters can be set on a Model instance.

Parameter Description
AttractionDistance Defines how close together particles must be in order to join together.
ParticleSpacing Defines the distance between particles when they become joined together.
MinMoveDistance Defines the minimum distance that a particle will move in an iteration during its random walk.
Stubbornness Defines how many join attempts must occur before a particle will allow another particle to join to it.
Stickiness Defines the probability that a particle will allow another particle to join to it.

The following hooks allow you to define the algorithm behavior in small, well-defined functions.

Hook Description
RandomStartingPosition() Returns a starting position for a new particle to begin its random walk.
ShouldReset(p) Returns true if the particle has gone too far away and should be reset to a new random starting position.
ShouldJoin(p, parent) Returns true if the point should attach to the specified parent particle. This is only called when the point is already within the required attraction distance. If false is returned, the particle will continue its random walk instead of joining to the other particle.
PlaceParticle(p, parent) Returns the final placement position of the particle.
MotionVector(p) Returns a vector specifying the direction that the particle should move for one iteration. The distance that it will move is determined by the algorithm.


Rendering is left to you. This code just gives you the location of the points and their hierarchy. But here is an example rendering in 2D with one million particles:


And here is a 3D example with 10 million particles. This image was ray traced in about 10 hours at 4096x4096px with 2048 samples per pixel. Full resolution here.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
c-plus-plus (18,567
cpp (1,316
high-performance (198