pub struct LSystem {
pub axiom: String,
pub rules: Vec<LSystemRule>,
pub angle_increment: f64,
pub step_size: f64,
}Expand description
Lindenmayer system (L-system) for generating fractal geometry strings.
Fields§
§axiom: StringAxiom (initial string)
rules: Vec<LSystemRule>Production rules
angle_increment: f64Angle increment in radians for turtle interpretation
step_size: f64Step size for turtle movement
Implementations§
Source§impl LSystem
impl LSystem
Sourcepub fn new(
axiom: &str,
rules: Vec<LSystemRule>,
angle_increment_deg: f64,
step_size: f64,
) -> Self
pub fn new( axiom: &str, rules: Vec<LSystemRule>, angle_increment_deg: f64, step_size: f64, ) -> Self
Create a new L-system.
Sourcepub fn evolve(&self, generations: u32) -> LSystemState
pub fn evolve(&self, generations: u32) -> LSystemState
Apply the production rules for n generations.
Sourcepub fn interpret(&self, state: &LSystemState) -> Vec<([f64; 2], [f64; 2])>
pub fn interpret(&self, state: &LSystemState) -> Vec<([f64; 2], [f64; 2])>
Interpret the L-system string as turtle graphics commands.
Returns a vector of line segments as pairs of 2D points.
Symbols: F = move forward (draw), f = move forward (no draw),
+ = turn left, - = turn right, [ = push state, ] = pop state.
Sourcepub fn koch_curve() -> Self
pub fn koch_curve() -> Self
Create an L-system for the Koch snowflake.
Sourcepub fn sierpinski() -> Self
pub fn sierpinski() -> Self
Create an L-system for the Sierpinski triangle.
Sourcepub fn dragon_curve() -> Self
pub fn dragon_curve() -> Self
Create an L-system for the dragon curve.
Sourcepub fn plant_branching() -> Self
pub fn plant_branching() -> Self
Create an L-system for plant branching.
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
Mutably borrows from an owned value. Read more
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.