oftenpaper.net

l-system ™


  1. axiom = {A};
    rules = {A -> {B, R, A, R, B}, B -> {A, L, B, L, A}};
    conversions = {A -> forward, B -> forward, L -> left, R -> right};
    
    (* state transformations *)
    forward[{z_, a_}] := {z + E^(I a), a};
    left[{z_, a_}] := {z, a + 2 Pi/6};
    right[{z_, a_}] := {z, a - 2 Pi/6};
    
    draw[n_] := Module[{program, zs},
      program = Flatten[Nest[# /. rules &, axiom, n]] /. conversions;
      zs = First /@ ComposeList[program, N@{0, 0}];
      Graphics[Line[{Re[#], Im[#]} & /@ First /@ Split[zs]]]];
    

This page is an excerpt from the sierpinski triangle page to end most sierpinski triangle pages ™.