Skip to content
Sample of Diffusion Limited Aggregation

complexification_net · diffusionLimitedAggregation

Diffusion Limited Aggregation

DLA is a simulated growth process: a sticky seed sits in a 2D field, wandering particles spawn along an outer circle, take unit-length random-walk steps, and stick to the cluster whenever they touch it. The resulting structure is a fractal coral-like dendrite with long channels and tremendous empty spaces (the 'fnords' Tarbell describes). It is an effective, slow growth model for natural systems such as the deposition of metals during an electrochemical reaction.

Original: https://web.archive.org/web/20041223173745/http://www.levitated.net/daily/levDLA.html

▶ Try the live demo (JS port) ▶ Run reference.py via Pyodide 10 formulas have instant JS ports. The Pyodide path runs the actual Python in your browser — first load is ~6 MB, then instant.

Family
complexification_net
Source
complexification.net
Evolution
growth
Render
grid_painting
Complexity
medium
Agents
8
Year
2001
Author
j.tarbell

Math essence

Witten-Sander diffusion-limited aggregation on a discrete lattice: at each step up to N walkers spawn at radius r_spawn and execute angle-uniform random-walk steps of length 1; a walker that enters an 8-neighborhood of any occupied cell is immediately absorbed (added to the cluster), while a walker that drifts beyond radius r_kill is recycled.

Parameters

Name Type Default Range Description
dim int 400 150–800 Square canvas side length
spawn_margin float 6 1–30 Distance beyond cluster radius where walkers spawn
kill_margin float 12 2–60 Distance beyond cluster radius where walkers are recycled
max_walkers int 64 1–256 Concurrent walkers per step
walk_steps_per_step int 64 1–512 Random walk steps each walker takes per simulation step
bg_color tuple 0,0,0 null–null Background RGB
fg_color tuple 255,240,220 null–null Cluster RGB
seed int null 0–999999 RNG seed

Reference

First 60 lines of reference.py. Full source: library_external/complexification_net/diffusionLimitedAggregation/reference.py

from __future__ import annotations

from typing import ClassVar

import imageio.v2 as imageio
import numpy as np


class DiffusionLimitedAggregation:
    family: ClassVar[str] = "complexification_net"
    sketch: ClassVar[str] = "diffusionLimitedAggregation"

    def __init__(
        self,
        dim: int = 400,
        spawn_margin: float = 6.0,
        kill_margin: float = 12.0,
        max_walkers: int = 64,
        walk_steps_per_step: int = 64,
        bg_color: tuple[int, int, int] = (0, 0, 0),
        fg_color: tuple[int, int, int] = (255, 240, 220),
        seed: int | None = None,
    ) -> None:
        self.dim = dim
        self.spawn_margin = float(spawn_margin)
        self.kill_margin = float(kill_margin)
        self.max_walkers = max_walkers
        self.walk_steps_per_step = walk_steps_per_step
        self.bg_color = np.array(bg_color, dtype=np.uint8)
        self.fg_color = np.array(fg_color, dtype=np.uint8)
        self._seed = seed
        self.cx = 0.0
        self.cy = 0.0
        self.cluster_radius = 1.0
        self.rng = np.random.default_rng(seed)
        self.canvas = np.full((dim, dim, 3), self.bg_color, dtype=np.uint8)
        self.occupied = np.zeros((dim, dim), dtype=bool)
        self.walkers_x = np.empty(0, dtype=np.float32)
        self.walkers_y = np.empty(0, dtype=np.float32)
        self.num_stuck = 0
        self.time = 0
        self.reset()

    def reset(self, seed: int | None = None) -> None:
        if seed is not None:
            self._seed = seed
        self.rng = np.random.default_rng(self._seed)
        self.canvas = np.full((self.dim, self.dim, 3), self.bg_color, dtype=np.uint8)
        self.occupied = np.zeros((self.dim, self.dim), dtype=bool)
        self.cx = self.dim / 2.0
        self.cy = self.dim / 2.0
        ix, iy = int(self.cx), int(self.cy)
        if 0 <= ix < self.dim and 0 <= iy < self.dim:
            self.occupied[iy, ix] = True
            self.canvas[iy, ix] = self.fg_color
        self.cluster_radius = 1.0
        self.walkers_x = np.empty(0, dtype=np.float32)
        self.walkers_y = np.empty(0, dtype=np.float32)
        self.num_stuck = 1
        self.time = 0

Try running it locally

The reference implementation is self-contained Python with numpy. Install the package and run:

python library_external/complexification_net/diffusionLimitedAggregation/reference.py

Need help? See Learn for the standard environment setup, or Playground for an in-browser sketchbook.

More from complexification.net

See all complexification_net artworks →