Space Colonization Algorithm: Grow SVG Trees
Grow a deterministic SVG tree toward an art-directed attraction envelope, then validate topology, bounds, reproducibility, and the edition receipt.
If an L-system writes a plant from a grammar, space colonization grows toward available room. This tutorial turns attraction points and distance rules into a reproducible SVG composition without calling the result botanical truth.
Why the space colonization algorithm differs
An L-system rewrites symbols according to a grammar, then interprets the resulting string as geometry. A space colonization algorithm begins with a spatial envelope of attraction points and grows a branching graph toward available regions. The distinction is not that one is natural and the other artificial. Both are authored models. The distinction is where the composition's pressure lives: rewrite rules versus occupied space.
That makes the space colonization algorithm useful for art direction. A canopy can be wide, narrow, hollow, leaning, or interrupted because the attraction envelope has that shape. Growth responds locally as points choose nearby nodes. A carved exclusion can preserve room for a title or create a deliberate void without trimming a finished tree after the fact.
This tutorial produces generative tree art, not a species model. It does not simulate light, vascular transport, ecology, gravity-driven mechanics, or optimal biological growth. The original algorithm paper describes tree-modeling goals; an SVG edition can borrow its nearest-node, influence, and kill rules while stating a narrower artistic claim.
The final object is a rooted parent graph plus a drawing recipe. Seed, envelope, distances, step length, tropism, exclusions, caps, and styling all belong in the edition receipt. A beautiful render without those inputs is a one-off image. A receipt makes the same SVG branching algorithm reproducible, editable, and honestly authored.
| Stage | Rule |
|---|---|
| Associate | Each point selects its nearest node within influence radius; lower node index wins an exact tie. |
| Average | Normalize each point direction, sum by parent, add declared tropism, normalize again. |
| Extend | Append one step-length child when finite, in bounds, outside exclusions, and collision-free. |
| Kill | Remove points within kill distance of any node. |
Build an art-directed attraction envelope
Begin the space colonization algorithm with a seeded pseudorandom generator and a declared coordinate system, such as a 760 by 520 SVG viewBox. Sample no more than 500 attraction points inside an envelope. An ellipse produces a balanced crown; a tapered polygon can lean; two lobes create a forked silhouette. The point cloud is not background noise. It is the negative and positive space toward which the graph competes.
Reject points inside or touching an exclusion mask, including explicitly supplied points. The lab exposes a circular cutout that can carve a calm arc through the canopy. Its fixed root must also remain strictly outside the mask; a mask that contains or touches the root is invalid rather than a stalled edition. Other editions might use author-drawn paths or rights-safe geometric masks. Do not trace a protected logo, illustration, or living artist's distinctive composition and call the result procedural originality. The envelope and mask should be your own or clearly licensed.
Point density changes opportunity. Uniform sampling gives every equal area a similar chance of attracting growth. Weighted sampling can bias an edge or crown, but record the weighting function. Use seeded randomness for generative art so the same seed and parameters reproduce the attraction set before any node is grown.
Place one root inside the bounds and outside exclusions. A short trunk may need to advance toward the cloud until a node enters an influence radius; otherwise every point is unreachable and the algorithm stalls immediately. That initialization policy is part of the recipe, not an implementation detail to hide after the output looks sparse.
Grow one deterministic SVG branching step
In each space colonization algorithm step, search all existing nodes for every remaining attraction point and find the nearest node within the influence radius. Use squared distance for comparison and a stable tie-breaker: when distances are equal within the chosen numeric rule, the lower node index wins. That small rule prevents iteration order or engine details from changing a symmetric edition.
Each assigned point contributes a unit vector from its chosen node toward the point. For a node with one or more assignments, sum those normalized vectors, add the declared tropism vector, then normalize the result. Multiply by the fixed step length and append one child whose parent is that node. If the direction is zero, non-finite, outside the viewBox, inside the exclusion, or too close to an existing node, reject the candidate and record the reason.
Do not average raw displacement vectors. Farther points would dominate even though the algorithm's association rule intends them as directions. Normalizing each contribution lets several nearby spatial demands vote. Tropism is an authored extra vote, not a scientific gravity model. Label its x and y components in the receipt.
After appending all children for the iteration, remove attraction points within the kill distance of any node. Then repeat with the remaining points. The first figure freezes this sequence: associate, average, extend, and kill. Its semantic table lists the operations so the colored arrows are not the only explanation.
Kill, stall, and stop honestly
The space colonization algorithm uses kill distance to remove an attraction point after growth comes close enough. It should usually be no greater than the influence radius. If kill exceeds influence, a point might be close enough to remove before it could contribute under some update orders. The lab rejects that relationship instead of producing a surprising edition. Step length should also remain positive and reasonably smaller than influence distance.
Several situations can stop growth. Every point may be outside all influence radii. Candidate children may collide with existing nodes, cross bounds, or land in an exclusion. Symmetric votes can sum to a zero direction. The node cap, point cap, or 400-iteration cap may be reached. These states are not all “complete.” Export a stop reason such as all-attractors-killed, stalled-no-associations, stalled-no-new-nodes, node-cap, or iteration-cap.
Duplicate nodes are especially dangerous. If a direction normalizes from a nearly zero vector or a step is smaller than numeric tolerance, a child can occupy its parent and grow an endless chain of identical coordinates. Require a minimum separation and reject non-finite coordinates before insertion. Stop after an iteration adds no nodes; never rely only on a generous maximum loop.
The result can still be aesthetically useful when points remain unreachable. Show their count and optionally draw them in a diagnostic layer. A sparse lower lobe might reveal an influence radius that is too small or an intentional exclusion that divides the envelope. The receipt preserves the difference between authored emptiness and algorithmic failure.
| Variant | Held constant | Observed fixture tendency |
|---|---|---|
| Base | Seed and envelope | Balanced local branching |
| Wider influence | Seed, kill, step, tropism | More shared direction |
| Smaller kill | Seed, influence, step, tropism | More nodes approach points |
| Right tropism | Seed, envelope, distances | Canopy leans right |
- Control
- The seed and all unlisted parameters stay fixed.
- Reading
- Each label describes this finite fixture, not a universal biological law.
Turn the skeleton into authored SVG
The space colonization algorithm returns a graph containing nodes with coordinates and parent indices. Validate that there is exactly one root, the root has no parent, every other parent index points to an earlier valid node, traversal reaches every node, and no cycle exists. Stable append order makes this check simple and lets the same receipt rebuild the same path list.
Render one SVG path per parent-child edge or combine compatible edges into longer paths. Use a declared viewBox so the edition scales without changing its geometry. Round exported numbers to a documented precision only after topology and bounds checks; premature rounding can merge nearby nodes. Add a title and description to the SVG, then keep decorative attraction points in an optional labeled group.
Width is a design mapping. A simple hierarchy can count descendants or depth and map thicker strokes toward the root. Clamp the range, use round line caps and joins, and avoid implying that width represents botanical age. Color, paper texture, branch taper, and crop are edition decisions layered on the validated skeleton.
SVG versus Canvas for generative art helps choose an output surface. SVG works well here because branches remain selectable paths and the viewBox is portable. For dense preview animation, Canvas may be faster, but the exported edition can still be SVG. Pen plotter hatching adds physical-production concerns if the paths move to paper.
Art-direct without hiding the parameters
Art-direct the space colonization algorithm by changing the envelope before rewriting the growth rule. A leaning cloud shifts the silhouette more legibly than an unexplained directional hack. A negative-space mask can open a reading zone. Point density can concentrate a crown. Tropism can introduce a restrained prevailing direction after those spatial choices are visible. The attraction envelope is the primary art direction.
Use a contact sheet to compare one seed across parameter changes. Hold seed and envelope constant, then vary influence radius, kill distance, or tropism one at a time. Next hold parameters constant and vary seed. This separates structural controls from sampling variation. Label every tile with its values and stop reason; otherwise a preferred thumbnail cannot be reproduced.
Influence radius controls how far a node can hear spatial demand. Too small can stall before the canopy connects. Too large can homogenize direction and reduce local branching. Kill distance controls how closely the skeleton approaches points before removing them. Step length affects resolution and collision risk. Tropism can bend the entire graph, but a strong value may overwhelm attraction votes.
The parameter figure shows fixture outcomes, not universal quality scores. Art judgment still decides balance, rhythm, crop, and whether the exclusion reads as intention. Flow-field plotter art offers another model where a vector field drives marks; here, attraction point growth competes through a growing parent graph. Keep that algorithmic difference visible in the caption and receipt.
- Validate one root, valid parents, finite in-bounds coordinates, and no cycles.
- Map width from declared hierarchy without claiming biological age.
- Apply the authored exclusion and keep rejected-growth counts.
- Choose a viewBox crop without altering graph coordinates.
- Export accessible SVG plus seed, parameters, stop reason, precision, and canonical hash.
Test topology and reproducibility
Test the space colonization algorithm against hostile inputs before admiring the render. Reject non-finite numeric seed values; bounded non-empty string seeds are valid and hashed as literal text. Also reject zero or negative distances, coordinates outside the viewBox, more than 500 points, more than 1,000 nodes, more than 400 iterations, and kill distance greater than influence radius. Bound any pasted JSON before parsing. An empty envelope should return a root-only graph with an explicit no-attractors state, not throw deep in nearest-neighbor code.
Fixtures should include unreachable points, a symmetric tie, dense points near the node cap, boundary points, an exclusion collision, and repeated versus changed seeds. Run the same config twice and compare a canonical receipt hash. Then change only the seed and assert that the attraction or node sequence changes. A deterministic failure is as important as deterministic success.
Validate finite in-bounds coordinates and a single-root acyclic parent graph after generation and again before SVG export. Confirm each non-root node has one valid parent. Stable tie-breaking and ordered JSON keys support reproducibility, but the receipt should name the hash method and numeric rounding. A hash identifies bytes; it does not certify aesthetic quality or authorship.
The downloadable procedural tree generation lab exposes these tests through a small public API used by committed Node tests. Its browser interface caps every run, makes the stop reason visible, and exports both SVG and JSON locally. It makes no network call and does not upload an edition.
Publish the generative tree edition receipt
An edition receipt should contain algorithm version, seed, viewBox, envelope, attraction count, influence radius, kill distance, step length, tropism, exclusion mask, iteration and node caps, stop reason, remaining attraction count, node count, style mapping, numeric precision, and canonical hash. Keep the source generator and exported files together when the piece is published.
Credit the lineage. Runions, Lane, and Prusinkiewicz describe the space colonization algorithm for tree modeling. Patrick, Rege, and Bailey explore artistic control extensions. SVG 2 paths defines the vector path surface used for the edition. Those sources inform the method; they do not grant biological realism or make this particular composition theirs.
The final anatomy figure separates graph, width hierarchy, exclusion, crop, and SVG export. That separation makes the creative contribution legible: the algorithm supplies a growth relation, while the artist authors the space, constraints, mapping, and edit. Physical plotting may introduce pen width, registration, and paper limits that need an additional production receipt.
A space colonization algorithm becomes more interesting when its constraints are exposed rather than romanticized. Publish the remaining points and stop reason. Name the work a stylized SVG branching study. Then the same evidence that supports reproducibility also reveals the artistic mind behind the envelope.
Runnable local artifact — This is a stylized algorithm study, not a botanical, ecological, or optimal-growth simulation.
Associate each attraction point with its nearest in-range node, average normalized directions with tropism, append bounded children, kill reached points, and stop on caps or stall.