Skip to main content

Module turtle

Module turtle 

Source
Expand description

Turtle interpretation: walk an L-system string into line segments, with a branch stack for [/]. A build-time step (runs inside Scene::configure, off the hot path) that produces the base geometry a generator scene caches and then only transforms per frame.

Commands (the common turtle vocabulary):

  • F, G — step forward, drawing a segment
  • f — step forward without drawing
  • + — turn left by the configured angle
  • - — turn right by the configured angle
  • [ — push position + heading
  • ] — pop position + heading
  • anything else — no-op (grammar variables such as X that only expand)

The space turtle (TurtleMode::Space) reads the same commands, with + and - yawing about its up vector, and five more, each turning by the configured angle:

  • &, ^ — pitch down, up (about the left vector)
  • \, / — roll left, right (about the heading)
  • | — turn around (yaw by 180 degrees)

[ and ] push and pop the whole frame. The flat turtle leaves those five symbols inert.

Structs§

Drawn
One draw step the Pen took: a segment in draw-step units, the generation it was drawn at, and whether it continues the segment drawn just before it.
Pen
The turtle an endless figure walks with, one symbol at a time.
Turtle3d
The space turtle’s state: a position and an orientation frame of three unit vectors, heading H, left L and up U, with U = H x L.

Enums§

TurtleMode
Which turtle walks the grammar: [generator] turtle (ADR-0258).

Functions§

normalize_fit
Center segs and uniformly scale them to fit within [-target, target] on the larger axis, so any figure (whatever its raw extent per depth) frames itself in the view. A degenerate (zero-extent) set is left untouched.
on_grid
p rounded to the nearest point of the GRID.
sphere_fit
Centre segs on their bounding box’s centre and scale them uniformly so every endpoint lies within a sphere of radius radius about the origin, and return the sphere’s radius after the fit — radius, or 0 for an empty or degenerate set, which is left untouched.
walk
Walk s into out (cleared first) as base geometry — positions only; the scene fills colour/width per frame. angle is in radians. Segments beyond max_segments are dropped and counted (the ADR-0007 cap is never silent): the returned usize is how many draw steps were dropped.
walk_3d_with_depths
walk_with_depths for the space turtle: s walked into 3D segments in out, with each segment’s generation depth in depths, index-aligned the same way and under the same cap. Both are cleared first; the returned usize is how many draw steps the cap dropped.
walk_with_depths
walk, plus the generation depth of every emitted segment written into depths (cleared first) — the branch-nesting level the turtle drew it at (ADR-0059’s lsystem colour axis). Depth 0 is the trunk; each unclosed [ is one more generation, so a segment’s depth is how many branch pushes are still open above it.