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.
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 });
}
}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
minRadius: number — Smallest allowed circle radius.maxRadius: number — Largest radius attempted before a candidate is shrunk to fit.maxAttempts: number — Random placements tried before the algorithm stops filling the space.padding: number — Minimum gap enforced between neighbouring circles.
Lineage
Frequently combined with
- HSL / Hue Cycle · 2 works
- Perlin / Simplex Noise · 2 works
- Bezier / Catmull-Rom Splines · 2 works
- Poisson Disk Sampling · 2 works
- Particle System · 2 works
- Polygon Mosaic · 2 works
- 3D Mesh / Geometry · 1 work
- Marching Squares / Contours · 1 work
- Fragment Shader (GLSL) · 1 work
- Physics Simulation · 1 work
- Modular Assembly / Parametric Character · 1 work
- Plotter-style Hatching · 1 work
Works using this algorithm (12)
Last updated 2026-07-16