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)

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.
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_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.