Home

Awesome

Read my Medium article to learn more about diffusion-limited aggregation and this project.

Additional media is available on my portfolio

This repo contains a series of visual experiments built with JavaScript that explore the topic of diffusion-limited aggregation (DLA) as a method for generating interesting 2D forms.

I am particularly interested in the application of such techniques in the context of digital fabrication, so these experiments will be more focused on schematic representations (colorless, vector-based, SVG/STL exports) over purely visual effects.

About diffusion-limited aggregation

Diffusion-limited aggregation (DLA) is a process in which randomly-moving particles diffuse through a medium and clump together (aggregate) over time to form long, fractal, branch-like chains (sometimes called Brownian trees). It closely models various interesting phenomena seen in nature at different scales and in different mediums.

A classic example is that of the formation of copper sulfate crystals in the presence of an electrodeposition cell. When electricity is applied, individual copper atoms are stripped from the system's anode and randomly float (diffuse) through the liquid medium until they come in contact with other copper atoms that have accumulated on the system's cathode where they form a strong molecular bond and aggregate over time.

Another example can be seen in the rather more violent phenomena of Lichtenberg figures, wherein an electrical discharge of very high voltage travels through an insulator like wood, burning a curious fractal branching structure in it's wake. In this example, it would seem that the electrical discharge itself diffuses through the wood, limited by the insulating nature of the wood, forming an "aggregate" of burnt wood as it progresses.

A note on lattices and parameterization

In classical implementations this algorithm acts upon a regular 2D grid of pixels wherein each "particle" can have up to 8 neighbors. Though simplistic, this so-called "on-lattice" approach can run at blistering speeds because no expensive distance calculations, spatial indexing, or collision detection is required - just array lookups.

However, this approach results in an inherently low fidelity raster image that has a pretty characteristic aesthetic style and limited usefulness in modern digital fabrication workflows. In the world of digital fabrication vector-based graphics are preferred because they can be easily transformed into machine toolpaths and manipulated in interesting ways in CAD software.

To achieve vector-based results from the DLA process one must move away from pixels and towards particles, which also affords one the ability for more parameterization that can be fun to explore creatively. For example, one could vary the size, shape, and movement behaviors of these particles to achieve interesting effects.

Keyboard commands

KeyResult
wToggle visibility of walkers
cToggle visibility of clustered particles
sToggle visibility of custom SVG shapes
rRestart simulation
fToggle frame
lToggle line rendering effect
eExport and initiate download of current drawing as SVG file
tToggle visibility of helpful text
SpacePause/unpause simulation

Parameters

ParameterValueDefaultDescription
CircleDiameterNumber5Default size of walkers, if none is provided through local Settings.
InitialClusterTypePoint, Ring, Random, or WallPointDefault initial cluster pattern, if none is provided through local Settings.
ShowClustersBooleantrueVisibility of clustered particles on load.
ShowWalkersBooleantrueVisibility of walkers on load.
ShowShapesBooleantrueVisibility of custom SVG shapes on load.
MaxWalkersNumber20000Maximum number of walkers - lower numbers mean better performance, but fewer hits.
WalkerSourceEdges, Circle, Random, Random-Circle, or CenterCenterWhere new walkers are spawned.
ReplenishWalkersBooleanfalseAdd new walkers whenever they become stuck to clusters.
BiasTowardsTop, Bottom, Left, Right, Edges, Center, Equator, or MeridianCenterDirection to move all walkers each iteration.
BiasForceNumber1Magnitude of force to move walkers towards their bias direction.
UseFrameBooleantrueConstrain sketch to a box centered on the screen.
FrameSizeNumber or [width, height]900Size of frame.
CaptureLinesBooleantrueEnable building of an internal buffer of line segments between all connected particles. Can be disabled if it impacts performance at large scales.
RenderModeShapes or LinesShapesMethod of drawing particles. Can draw the shapes as they exist (Shapes), or only draw lines between connected particles (Lines).
UseColorsBooleanfalseEnable the use of colors defined by objects below.
UseStrokeBooleanfalseDraws all circles/polygons with a 1px stroke matching the background color.
BackgroundColorObject with h, s, b propertiesColor of canvas background in HSB format.
WalkerColorObject with h, s, b propertiesColor of walkers in HSB format.
ClusterColorObject with h, s, b propertiesColor of clustered particles in HSB format.
ShapeColorObject with h, s, b propertiesColor of custom SVG shapes in HSB format.
LineColorObject with h, s, b propertiesColor of lines when using Lines for RenderMode.
FrameColorObject with h, s, b propertiesColor of frame, if enabled with UseFrame.

Packages used

Running locally

  1. Ensure you're running Node v16.
    • If you're on a Mac running NVM, run the command nvm use to run the version specified in .nvmrc.
    • If you're on Windows, use NVM to install and switch to Node v16.17.0.
  2. Run npm install in both the root (/) and ./core folders.
  3. Run npm run serve in the root folder to start a local development server and launch it in a browser.

To statically build the code in this repo, run npm run build in the root folder.

Going further

The code in this repo can be improved or optimized in a few ways to achieve faster performance and larger scales. Here are some ideas that come to mind:

  1. Rather than using brute-force movement and collision detection (which limit overall scale + speed), implement an algorithm like Michael Fogleman's dlaf. This may mean that one would have to do away with variable particle shapes and sizes, but I imagine variable sizes could be accommodated with some tweaking.
  2. Port code over to a more performant language / library like openFrameworks or Cinder.

References

Samples

Basic DLA Directional bias Different sizes Different shapes SVG input Basic DLA with color Line rendering effect