Anabaena

L-System (Lindenmayer system) for Rust.

Features

Examples

Algae

Taken from the Wikipedia article on L-Systems, the following is an implementation of the algae example:

```rust use anabaena::{LSystem, LRulesHash, LRulesQualified, LRulesSet};

let rules: LRulesHash<(), char> = LRulesHash::from([ ( 'A', LRulesQualified { nocontext: Some(vec![ (1, Box::new(|| vec!['A', 'B'])), ]), ..LRulesQualified::default() } ), ( 'B', LRulesQualified { nocontext: Some(vec![ (1, Box::new(|| vec!['A'])), ]), ..LRulesQualified::default() } ) ]);

let axiom: Vec = vec!['A'];

let mut lsystem = LSystem { string: axiom, rules, context: (), mkcontext: Box::new(|, _| ()), };

asserteq!(lsystem.next(), Some("AB".chars().collect())); asserteq!(lsystem.next(), Some("ABA".chars().collect())); asserteq!(lsystem.next(), Some("ABAAB".chars().collect())); asserteq!(lsystem.next(), Some("ABAABABA".chars().collect())); asserteq!(lsystem.next(), Some("ABAABABAABAAB".chars().collect())); asserteq!(lsystem.next(), Some("ABAABABAABAABABAABABA".chars().collect())); assert_eq!(lsystem.next(), Some("ABAABABAABAABABAABABAABAABABAABAAB".chars().collect())); ```

Examples with Turtle.rs

Most of the other examples in the Wikipedia article are implemented in the examples/ folder, which use the turtle.rs library to render the results. You can run the B-Tree example, for instance, with the following command:

bash cargo run --example btree