pub struct Pen { /* private fields */ }Expand description
The turtle an endless figure walks with, one symbol at a time.
The flat mode reads + and - alone, as the plane walk does, and leaves
the space symbols inert; the space mode reads them all. Either way the
state is a Turtle3d, so a flat figure lies in the xy plane.
The branch stack is reserved once, at the bound the grammar’s
brackets allow (grammar::bracket_bound), and a push past it is refused
rather than grown, so stepping never allocates. Only an unbalanced grammar
reaches the bound; there a later ] restores an older state.
Its position is f64 on on_grid’s grid, not the f32 the cached
walk uses, and the turtle’s own pos is unused: the frame turns in f32,
the pen moves in f64. Every position an endless figure holds is a grid
point, so a re-base by a whole number of steps (shift) is
exact, and a step’s length keeps its precision however far the pen walks.
Implementations§
Source§impl Pen
impl Pen
Sourcepub fn new(mode: TurtleMode, angle: f32, stack_bound: usize) -> Self
pub fn new(mode: TurtleMode, angle: f32, stack_bound: usize) -> Self
A pen at the origin for mode, turning by angle radians, with room
for stack_bound open branches.
Sourcepub fn read(&mut self, ch: char) -> Option<Drawn>
pub fn read(&mut self, ch: char) -> Option<Drawn>
Read one symbol, and say what it drew, if anything.
Sourcepub fn clear_branches(&mut self)
pub fn clear_branches(&mut self)
Close every open branch where the turtle stands, and lift the pen: a restarted stream opens its brackets from nothing.
Sourcepub fn stack_capacity(&self) -> usize
pub fn stack_capacity(&self) -> usize
The branch stack’s reserved room.