L-system

L-system functionality as a Role that may be mixed in to a scalar.

# L-system functionality 
role Lindenmayer {
    has %.rules;
    method succ {
        self.comb.map( { %!rules{$^c} // $c } ).join but Lindenmayer(%!rules)
    }
}

# Testing
my $rabbits = 'I' but Lindenmayer({I => 'M', M => 'MI'});

.say for $rabbits++ xx 6;

Output:

I
M
MI
MIM
MIMMI
MIMMIMIM

Also see:

Dragon_curve#Raku

Hilbert_curve#Raku

Koch_curve#Raku

Peano_curve#Raku

Penrose_tiling#Raku

Sierpinski_curve#Raku

Sierpinski_arrowhead_curve#Raku

Sierpinski_square_curve#Raku

among others...

Last updated