Space filling curves, fractal dimension d = 2.0

LSystem[axiom_,rules_List,n_Integer?NonNegative,False]:=LSystem[axiom,rules,n,False]=Nest[StringReplace[#,rules]&,axiom,n]

LSystem[axiom_,rules_List,n_Integer?NonNegative,True]:=LSystem[axiom,rules,n,True]=NestList[StringReplace[#,rules]&,axiom,n]

LSeed["Hilbert curve"]="+RF-LFL-FR+";LSeed["Moore curve"]="+LFL+F+LFL-";

LRules["Hilbert curve"]={"L"->"+RF-LFL-FR+","R"->"-LF+RFR+FL-"};LRules["Moore curve"]={"L"->"-RF+LFL+FR-","R"->"+LF-RFR-FL+"};

LPoints[lstring_String]:=LPoints[lstring]=Map[First,Split[Chop[Map[First,
FoldList[Function[{pta,c},
Switch[c,
"+",{pta[[1]],pta[[2]]+90Degree},
"-",{pta[[1]],pta[[2]]-90Degree},
"F",{{pta[[1]][[1]]+Cos[pta[[2]]],pta[[1]][[2]]+Sin[pta[[2]]]},pta[[2]]},
_,pta]],
{{0,0},0.},
Characters[lstring]]]]]]

LPoints[lstring_String,level_Integer?NonNegative]:=Map[(2^(5-level)*#+((2^(5-level)-1)/2))&,LPoints[lstring]]

LLine[lstring_String,level_Integer?NonNegative]:={AbsoluteThickness[2*(5-level)],ColorData["DarkRainbow"][level/5],Line[LPoints[lstring,level]]}

Manipulate[
Graphics[If[showPreviousLevels==False,
LLine[LSystem[LSeed[whichcurve],LRules[whichcurve],n-1,showPreviousLevels],n],MapIndexed[LLine[#1,First[#2]]&,LSystem[LSeed[whichcurve],LRules[whichcurve],n-1,True]]]],{{n,1,"iterations"},Range[1,6,1],ControlType->RadioButton},{{whichcurve,"Hilbert curve",""},{"Hilbert curve","Moore curve"},ControlType->RadioButtonBar},{{showPreviousLevels,False,"show multiple iterations"},{True,False}},SaveDefinitions->True]

Credit: Robert Dickau

Creation of this notebook was supported by IT Academy program of Information Technology Foundation for Education (HITSA).