(*Adapted by Rafael Luís: rafaelluis@netmadeira.com from Robert M.Dickau
updated to Mathematica v.10 by Ross Moore *)

Lmove[ z_String, Ldelta_ ] :=
    Switch[ z,
        "+", Ltheta += Ldelta;,
        "-", Ltheta -= Ldelta;,
        "F", Lpos += {Cos[Ltheta], Sin[Ltheta]},
        "B", Lpos -= {Cos[Ltheta], Sin[Ltheta]},
         _ , Lpos += 0. ];

LSystem::usage =
    "LSystem[axiom, {rules}, n, Ldelta:90 Degree]
    creates the L-string for the nth iteration of
    the list 'rules', starting with the string 'axiom'.";


LSystem[ axiom_, rules_List,
    n_Integer, Ldelta_:N[90 Degree]] :=
    
    Nest[ StringReplace[#, rules]&, axiom, n ];

Off[General::spell1];


LShow[lstring_String, Ldelta_:N[90 Degree]] :=
   (Lpos={0.,0.};
    Ltheta=0.;
      Graphics[{Blue,Thickness[.001],Line[
        Prepend[
          DeleteCases[
            Map[Lmove[#, Ldelta]&, Characters[lstring]],
           Null ],
        {0,0}]]},
     AspectRatio -> Automatic]);


LShowColor[lstring_String, Ldelta_:N[90 Degree]] :=
   (Lpos = {0., 0.};
    Ltheta = 0.;
    templist =
      Map[ Line,
        Partition[
          Prepend[
            DeleteCases[
              Map[ Lmove[#, Ldelta]&, Characters[lstring] ],
             Null],
           {0,0}],
         2,1]];

    ncol = N[Length[templist]];

    huelist = Table[ Hue[k/ncol], {k, 1., ncol} ];

     Graphics[{Thickness[.001],
        N[Flatten[Transpose[{huelist, templist}]]]},
     AspectRatio -> Automatic]);

On[General::spell1];

Manipulate[LShow[ (* Koch curve *)
    LSystem["F", {"F" -> "F+F--F+F"},k],
        N[60 Degree]]
,{{k,1,"depth"},Range[6]}]

Manipulate[LShowColor[ (* Koch curve *)
    LSystem["F", {"F" -> "F+F--F+F"},k],
        N[60 Degree]]
,{{k,1,"depth"},Range[6]}]