L-System

Rewrite an axiom with Lindenmayer production rules over N generations, then draw the result with a turtle.

What it does

L-System grows a fractal or branching shape in one of two ways.

From a typed grammar. A starting string (the axiom) is rewritten by a set of symbol-replacement rules, once per iteration, and the result is walked with a turtle: forward moves draw a line, +/- turn, and [/] branch and return. Pick a built-in preset (Sierpinski, Koch, Dragon, Hilbert 2D, Plant, Hilbert 3D, Tree 3D), or set Preset to Custom and write your own axiom and rules. More iterations means more rewrite passes, a denser and more detailed pattern, and more points.

From a drawn generator. Wire a path from Pen or Edit into the Generator input and that drawn path becomes the rule: every segment of the path is replaced by a shrunken copy of the whole path, repeatedly, so a single bump turns into a Koch-style fractal. Editing the drawn path upstream regenerates the fractal live. With a generator wired, the axiom, rules, and preset are ignored. Iterations sets how deep the substitution recurses.

The same turtle draws the line either way. In 2D mode it draws a flat vector shape. In 3D mode it draws a polyline in the scene and turns can pitch and roll out of the plane, which is what the Hilbert 3D and Tree 3D presets use to fill space and fan branches. Angle, Step, and Width Scale can each be wired from a Distance Field or Gradient instead of held constant, so the pattern bends, stretches, or thins as it walks across a field. Every visited position is also emitted as points, ready to drive instancing.

When to use it

ParameterTypeDefault
angle_fieldOneOf([FieldOf(Scalar), Number])
step_fieldOneOf([FieldOf(Scalar), Number])
width_fieldOneOf([FieldOf(Scalar), Number])
generatorOneOf([Collection])
presetString"Custom"
axiomString"F"
rulesString"F=F+F-F-F+F"
iterationsNumber4
modeString"2D"
stepNumber10
angleNumber90
initial_headingNumber90
output_originString"Centered"
initial_widthNumber2
width_scaleNumber0.700
stroke_colorColorrgba(1.00, 1.00, 1.00, 1.00)
max_pointsNumber100000
opacityNumber1

Gotchas

Iterations grows the shape exponentially, whether a grammar is being expanded or a drawn generator recursed. Max Points caps the turtle's output so a runaway setting cannot hang the graph; raise it deliberately if a dense preset (Plant at high Iterations) or a many-segment drawn generator gets clipped.

Only one visual output is drawn at a time: 2D mode draws Shapes, 3D mode draws Geometry, never both. Switch Mode to change which one is live. Points is always produced but never draws on its own, being instancing data for a downstream node.

Wiring the Generator input switches the node into drawn-generator mode: the drawn path becomes the rule and the Axiom, Rules, Preset, and Angle fields no longer apply. Disconnect it to return to the typed grammar.

When Preset is anything other than Custom, the built-in axiom, rules, and angle take over and the Axiom, Rules and Angle fields are ignored. Set Preset to Custom to use your own values. This applies to the typed-grammar mode only, since a wired Generator overrides all of them.

Rules take one line per symbol, symbol=replacement. Blank lines and lines starting with # are ignored, so a grammar can carry comments. A symbol with no rule passes through unchanged each pass.

Worked example

  1. Add an L-System node. Leave Preset on Sierpinski to see a result immediately.

  2. Raise Iterations to add detail, watching point count and render time grow fast.

  3. Set Preset to Custom, then write your own Axiom (e.g. F) and Rules (e.g. F=F+F-F-F+F) to design a new pattern.

  4. Switch Mode to 3D and pick Hilbert 3D or Tree 3D for a spatial structure whose turns pitch and roll out of the plane.

  5. Alternatively, draw a shape with Pen, wire it into Generator, and raise Iterations to turn the sketch into a fractal. Edit the sketch and it regenerates live.

  6. Wire a Gradient into Step Field to make the stride vary across the canvas.

  7. Adjust Stroke Color, Initial Width, and Width Scale to style the line.

See also

Pen · Pattern · Noise · Geometry (meshes)