Circle Packing

No single origin work. Circle packing is classical geometry (Apollonian gaskets in antiquity; Descartes' circle theorem, 1643), while its generative-art form — a grow-and-reject field of non-overlapping circles, often weighted by an image — is a diffuse coding-community pattern rather than a datable first.

community / folk Name — A descriptive category label, not a coined or eponymous name; no single coiner of the term is attested.

In one line Filling a region with non-overlapping circles of varying size. In generative art it is usually done by a grow-and-reject loop rather than an exact optimal packing, giving dense, organic, bubble-like fields.

Circle Packing · Open in new tab ↗ · Motion begins only when you press Run.

The code

The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.

circle-packing/index.html
const SEED = Math.floor(Math.random()*1e9);

function setup() {
  randomSeed(SEED);
  const s = Math.min(windowWidth, windowHeight);
  createCanvas(s, s);
  background('#f0ede4');
  noFill();
  strokeWeight(1.5);

  // Random-rejection circle packing.
  // For each attempt: sample a radius from a heavy-tail distribution,
  // sample a center, accept if it overlaps none of the previously placed.
  const placed = [];
  const MAX_PLACED = 320;
  const MAX_ATTEMPTS = 40000;
  const palette = ['#1a1a1a', '#c1502e', '#1f4068', '#e2a829', '#3a7d44'];

  let attempts = 0;
  while (placed.length < MAX_PLACED && attempts < MAX_ATTEMPTS) {
    attempts++;
    // bias toward smaller radii
    const u = random();
    const r = lerp(s * 0.004, s * 0.08, u * u * u);
    const x = random(r, width - r);
    const y = random(r, height - r);

    let ok = true;
    for (let i = 0; i < placed.length; i++) {
      const c = placed[i];
      const dx = x - c.x, dy = y - c.y;
      if (dx*dx + dy*dy < (r + c.r) * (r + c.r)) { ok = false; break; }
    }
    if (!ok) continue;

    stroke(palette[(placed.length) % palette.length]);
    circle(x, y, r * 2);
    placed.push({ x, y, r });
  }
}

Open the demo source ↗

How it works

The common "grow" approach: 1. Drop a candidate circle at a random position (rejecting it if it already overlaps an existing circle or leaves the region). 2. Grow accepted circles outward a little each frame, stopping each one the moment it touches another circle or the boundary. 3. Keep adding candidates into the remaining gaps until the region is full or an attempt budget is exhausted. A spatial grid or nearest-neighbour structure keeps the overlap tests fast. Variants weight circle sizes by an image's brightness (for stippling/portraits) or relax positions to remove overlaps (Apollonian-style tight packings).

Parameters

Lineage

Precedents
Jared Tarbell
Related
Poisson Disk Sampling, Voronoi Diagram

Frequently combined with

Works using this algorithm (12)

Breathe You
raregonzo
Coalition
generative-artworks
Daisies
natthakit-susanthitanon-nsmag
Figments
amber-vittoria
Octo Garden
rich-lord
Organized Disruption
joshua-davis
Paramecircle
alexander-reben
Pizza 1o1
kala
Proscenium
remnynt
Scatter Process[or]
kelly-milligan
Structures
hevey
Thereidoscope
daim-aggott-honsch

Last updated 2026-07-16