anabaena

Crates.ioanabaena
lib.rsanabaena
version0.7.0
sourcesrc
created_at2023-02-02 15:37:46.353725
updated_at2023-02-13 10:44:17.783777
descriptionL-System (Lindenmayer system) framework for Rust
homepage
repositoryhttps://github.com/athanclark/anabaena
max_upload_size
id774868
size60,149
Athan Clark (athanclark)

documentation

README

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:

use anabaena::{LSystem, LRulesHash, LRulesSet, Total};
use std::collections::HashMap;
use streaming_iterator::StreamingIterator;

let rules: LRulesHash<(), char, LRulesSet<char>> = |_| HashMap::from([
    (
        'A',
        LRulesSet::new(vec![
            (1, vec!['A', 'B']),
        ]),
    ),
    (
        'B',
        LRulesSet::new(vec![
            (1, vec!['A']),
        ]),
    )
]);

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

let mut lsystem: LSystem<_,_,_, Total> = LSystem::new(
    axiom,
    rules,
);

assert_eq!(lsystem.next(), Some(&"AB".chars().collect()));
assert_eq!(lsystem.next(), Some(&"ABA".chars().collect()));
assert_eq!(lsystem.next(), Some(&"ABAAB".chars().collect()));
assert_eq!(lsystem.next(), Some(&"ABAABABA".chars().collect()));
assert_eq!(lsystem.next(), Some(&"ABAABABAABAAB".chars().collect()));
assert_eq!(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:

cargo run --example btree
Commit count: 25

cargo fmt