pub struct LSystem {
pub alphabet: Vec<char>,
pub rules: HashMap<char, String>,
pub axiom: String,
pub angle_deg: f64,
pub step_size: f64,
}Expand description
A deterministic context-free L-system (D0L-system).
An L-system generates strings by parallel rewriting: at each step, every character in the current string is replaced according to the production rules simultaneously.
Fields§
§alphabet: Vec<char>The alphabet of valid symbols.
rules: HashMap<char, String>Production rules mapping symbols to replacement strings.
axiom: StringThe starting string (axiom).
angle_deg: f64Default turning angle in degrees (for turtle interpretation).
step_size: f64Default step size (for turtle interpretation).
Implementations§
Source§impl LSystem
impl LSystem
Sourcepub fn new(
alphabet: Vec<char>,
rules: Vec<ProductionRule>,
axiom: impl Into<String>,
) -> Self
pub fn new( alphabet: Vec<char>, rules: Vec<ProductionRule>, axiom: impl Into<String>, ) -> Self
Create a new L-system.
Sourcepub fn koch_curve() -> Self
pub fn koch_curve() -> Self
Koch curve L-system (angle = 60°).
Sourcepub fn sierpinski() -> Self
pub fn sierpinski() -> Self
Sierpinski triangle L-system (angle = 120°).
Sourcepub fn dragon_curve() -> Self
pub fn dragon_curve() -> Self
Dragon curve L-system (angle = 90°).
Sourcepub fn plant_branching() -> Self
pub fn plant_branching() -> Self
Plant branching L-system (angle = 25°).
Sourcepub fn evolve(&self, n: usize) -> LSystemEvolution
pub fn evolve(&self, n: usize) -> LSystemEvolution
Evolve the L-system for n generations, returning the state.
Sourcepub fn interpret(&self, state: &LSystemEvolution) -> Vec<(Point2, Point2)>
pub fn interpret(&self, state: &LSystemEvolution) -> Vec<(Point2, Point2)>
Interpret a previously evolved state as turtle graphics segments.
Sourcepub fn iterate_length(&self, n: usize) -> usize
pub fn iterate_length(&self, n: usize) -> usize
Count the length of the string after n iterations without building it.
Sourcepub fn turtle_interpret(
&self,
n: usize,
step_size: f64,
angle_deg: f64,
) -> Vec<(Point2, Point2)>
pub fn turtle_interpret( &self, n: usize, step_size: f64, angle_deg: f64, ) -> Vec<(Point2, Point2)>
Interpret the generated string as turtle graphics commands.
F,G: move forward bystep_size+: turn left byangle_degdegrees-: turn right byangle_degdegrees[: push state]: pop state
Returns a list of line segments as (start, end) pairs.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LSystem
impl RefUnwindSafe for LSystem
impl Send for LSystem
impl Sync for LSystem
impl Unpin for LSystem
impl UnsafeUnpin for LSystem
impl UnwindSafe for LSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.