5
27/2/2015 LSystem Rules http://www.cs.unm.edu/~joel/PaperFoldingFractal/Lsystemrules.html 1/5 Lindenmayer Systems: Details Overview As a biologist, Aristid Lindenmayer studied growth patterns various types of algae. In 1968 he developed Lindenmayer systems (or Lsystems) as a mathematical formalism for describing the growth of simple multicellular organisms. More recently, Lsystems have found several applications in computer graphics. Two principal areas include generation of fractals and realistic modeling of plants. Basically, a Lindenmayer system begins with a string of symbols called the axiom, and applies to the axiom a set of production rules which are used to rewrite the axiom. For example, let the axiom of a Lindenmayer system be the string of three symbols 'peg', and let the set of production rules be the single rule: 'e=i'. This is summarized in the following table: axiom: peg rules: e=i When the rule is applied to the axiom, each 'e' symbols in the axiom is replaced with an 'i' symbol. Thus, the axiom 'peg' becomes 'pig'. This new string 'pig' is called the first generation of the L system since it is the result of applying the rules to the axiom one time. The second generation of this Lsystem is the result of applying the rules to the first generation. Since there are no 'e' symbols in the first generation, there is nothing for the rule to replace. Thus the second generation is also the string 'pig'. This rather boring Lsystem is summarized below: Boring LSystem axiom: peg rules: e=i generation 1: pig generation 2: pig generation 3: pig Lsystems are more interesting when the rules are recursive. A recursive rule is a rule that replaces a symbol with a copy of itself plus something extra. An example of a recursive rule is 'e = eie'. The table below shows the first three generations of an Lsystem with this recursive rule: Recursive LSystem axiom: peg rules: e = eie generation 1: peieg generation 2: peieieieg generation 3: peieieieieieieieg

L System Rules

Embed Size (px)

DESCRIPTION

jhhj

Citation preview

  • 27/2/2015 LSystemRules

    http://www.cs.unm.edu/~joel/PaperFoldingFractal/Lsystemrules.html 1/5

    LindenmayerSystems:DetailsOverview

    Asabiologist,AristidLindenmayerstudiedgrowthpatternsvarioustypesofalgae.In1968hedevelopedLindenmayersystems(orLsystems)asamathematicalformalismfordescribingthegrowthofsimplemulticellularorganisms.Morerecently,Lsystemshavefoundseveralapplicationsincomputergraphics.Twoprincipalareasincludegenerationoffractalsandrealisticmodelingofplants.

    Basically,aLindenmayersystembeginswithastringofsymbolscalledtheaxiom,andappliestotheaxiomasetofproductionruleswhichareusedtorewritetheaxiom.

    Forexample,lettheaxiomofaLindenmayersystembethestringofthreesymbols'peg',andletthesetofproductionrulesbethesinglerule:'e=i'.Thisissummarizedinthefollowingtable:

    axiom: pegrules: e=i

    Whentheruleisappliedtotheaxiom,each'e'symbolsintheaxiomisreplacedwithan'i'symbol.Thus,theaxiom'peg'becomes'pig'.Thisnewstring'pig'iscalledthefirstgenerationoftheLsystemsinceitistheresultofapplyingtherulestotheaxiomonetime.

    ThesecondgenerationofthisLsystemistheresultofapplyingtherulestothefirstgeneration.Sincethereareno'e'symbolsinthefirstgeneration,thereisnothingfortheruletoreplace.Thusthesecondgenerationisalsothestring'pig'.ThisratherboringLsystemissummarizedbelow:

    BoringLSystemaxiom: pegrules: e=igeneration1: piggeneration2: piggeneration3: pig

    Lsystemsaremoreinterestingwhentherulesarerecursive.Arecursiveruleisarulethatreplacesasymbolwithacopyofitselfplussomethingextra.Anexampleofarecursiveruleis'e=eie'.ThetablebelowshowsthefirstthreegenerationsofanLsystemwiththisrecursiverule:

    RecursiveLSystemaxiom: pegrules: e=eiegeneration1: peieggeneration2: peieieieggeneration3: peieieieieieieieg

  • 27/2/2015 LSystemRules

    http://www.cs.unm.edu/~joel/PaperFoldingFractal/Lsystemrules.html 2/5

    Inthefirstgeneration,thesingle'e'symbolintheaxiomwasreplacedwith'eie'creatingthestring'peieg'.SincetheruleinthisLsystemisrecursive,thefirstgenerationstringhastwonew'e'symbols,eachofwhichgetreplacedwith'eie'inthesecondgeneration...andsoitgoes.

    ThenextsectionsummarizesthedefinitionofanLsystemmoreformally.

    DefinitionofanLSystem

    AnLsystemisaformalgrammarconsistingof4parts:

    1. Asetofvariables:symbolsthatcanbereplacedbyproductionrules(seebelow).IntheFractalGrowersoftware,variablescanbeanyofthe26lowercaseEnglishlettersathroughz

    2. Asetofconstants:symbolsthatdonotgetreplaced.IntheFractalGrowersoftware,theconstantsareanyofthefollowingsymbols:!,[,],+,.

    3. Asingleaxiomwhichisastringcomposedofsomenumberofvariablesand/orconstants.Theaxiomistheinitialstateofthesystem.

    4. Asetofproductionrulesdefiningthewayvariablescanbereplacedwithcombinationsofconstantsandothervariables.Aproductionconsistsoftwostringsthepredecessorandthesuccessor.

    GraphicInterpretationofStrings

    RecursiveLsystems,liketheonedescribedabove,oftenproduceintricatelycomplexpatternsthatareselfsimilaracrossmultiplescales.Thesepatternsarealmostimpossibleforahumantoperceivedirectlyfromlongstringsofsymbols.Aswithmanytypesofdata,agraphicalrepresentationofthestringscanexposethesepatterns.

    ThemostcommongraphicalinterpretationappliedtoLSystemsisbasedonturtlegraphicswhichisthebestknownfutureoftheLogoprogramminglanguage.Logowasinventedin1967byWallyFeurzeigandSeymorurPapertasakidfriendlywayofteachingcomputerscience.Theturtleinturtlegraphicsisanonscreencursor(oronfloorrobot)whichcanbegivendrawing(ormovement)instructionssuchasmoveforwardbyaspecifieddistanceorturnrightorleftbyaspecifiedangle.Traditionallythecursorinturtlegraphicsisrepresentedpictoriallyasaturtleicon.

    WhenapplyingturtlegraphicstoLsystems,astateoftheturtleisdefinedasaquadruple(x,y,a,c).TheCartesiancoordinates(x,y)representtheturtle'sposition.Theanglea,calledtheheading,isinterpretedasthedirectioninwhichtheturtleisfacing.Thecolorcisinterpretedasthecolorpenthattheturtlecurrentlyhaspressedtothefloorsothatanymovementoftheturtlewillcreatealineofthatcolor.Giventhestepsizedandtheangleincrementb,theturtlecanrespondtosymbolsinanLsystemstringaccordingtothefollowinginstructions:

    f

    Moveforward(inthedirectionofthecurrentheading)adistancedwhiledrawingalineofcolorc.Thestateoftheturtlechangesto(x',y',a,c),where

  • 27/2/2015 LSystemRules

    http://www.cs.unm.edu/~joel/PaperFoldingFractal/Lsystemrules.html 3/5

    x'=x+dcos(a)andy'=y+dsin(a).

    h Sameasf.

    g Sameasfexceptnolineisdrawn.

    !

    Likethefandhsymbols,the!symbolmovestheturtleforward.Unlikethefandhsymbols,thedistancethatthe!symbolmovestheturtleisafunctionofthesymbol'sage.

    The!symbolisaconstant,soonceitisaddedtoastring,itremainsinthestringforallfuturegenerations.EveryNEW!symbolmovestheturtlethesamedistanceasdoeseveryf,g,andhsymbol.Everygenerationthata!symbolages,itslengthisdividedbythevalueofShrinkage.Thus,aShrinkagevalue>1makesolder!symbolsshorter,andaShrinkagevalue

  • 27/2/2015 LSystemRules

    http://www.cs.unm.edu/~joel/PaperFoldingFractal/Lsystemrules.html 4/5

    thesesymbolsareignoredbytheturtle,theyarestillusefulintheLsystemgrammarforbuildingstringstructurescontainingsymbolsnotignoredbytheturtle.

    Noteoncolor:thevariables'a'through'e'onlyeffectthecolorwhenthe'colorfandhsegmentsbyimbeddedvariables'radiobuttonisselectedonthecolortaboftheLSystemcontrolpanel.Ifthisradiobuttonisnotselected,thentheturtleignoresthe'a'through'e'symbols,andthecolorofeachlinesegmentisdeterminedbythelocationofeachforhinthestring:fandhsymbolsatthebeginningofthestringdrawredsegments,inthemiddleofthestringdrawgreensegments,andattheendofthestringdrawpurplesegments.

    Noteonsteplength:InLsystemsthatdonotusethe'!'symbol,thesteplengthhasnoeffectontheappearanceofdrawing.Thisisbecause,all'f'and'h'symbolsaredrawnwiththesamesteplength,thenthecompletedrawingisscaledsoastofillthedrawingwindow.Alargestepsizewilljustcausethesoftwaretoscaledownthefinaldrawingmore.However,whenthe'!'isused,thenthesteplengthhasagreateffectonthedrawingsince'f'and'h'symbolsalwaysmoveforwardadistanceequaltothesteplengthwhereas'!'symbolsmoveforwardadistanceequaltothesteplengthraisedtothepowerequaltothesymbol'sage.

    Example:DragonCurve

    Manyfractals(oratleasttheirfiniteapproximations)canbethoughtofassequencesoflinesegments.

    Thedragoncurveisonesuchfractal,anditsfiniteapproximationcanbecreatedwithanLSystem:DragonCurveLSystemvariables: fhconstants: +axiom: f

    rules: f=fhh=f+hangleincrement: 90degreesgeneration1: fhgeneration2: fhf+hgeneration3: fhf+hfh+f+hgeneration4: fhf+hfh+f+hfhf+h+fh+f+h

    ThisLSystemhastworules:oneforreplacing'f'symbolsandoneforreplacing'h'symbols.Therefore,both'f'and'g'arevariablesoftheLSystem.The'+'and''symbolsareconsideredconstantsbecausetherearenorulesinthesystemforreplacingthesetwosymbols.Theaxiomofthesystemisasingle'f'symbol.Therefore,whencreatingthefirstgeneration,theruleforreplacing'h'symbolsisnotused.

    Theredandgreencolorsinthetablehelpmakethesubstitutionprocesseasiertoperceive.Ateachgeneration,thenewsymbolsthatresultfromreplacingan'f'symbolareshowningreen,andthenewsymbolsthatresultfromreplacingan'h'symbolareshowninred.Eachsymbolthatismorethenonegenerationoldisshowninblack.Onlyconstantscanbemorethenonegenerationold,

  • 27/2/2015 LSystemRules

    http://www.cs.unm.edu/~joel/PaperFoldingFractal/Lsystemrules.html 5/5

    becausevariablesarealwaysreplacedateachgeneration.Onlysomeofthe'+'and''symbolsareshowninblackbecauseonlythesearemorethenonegenerationold.

    Let'stakeastepbystepexaminationofthesecondgenerationofthisLSystem.Thegeneration2stringis:'fhf+h'.Assumingthattheinitialheadingoftheturtleisupwardonthescreen,thenthefirst'f'willdrawalinestraightup.The''causestheturtletochangeitsheadingby90degreestobepointeddirectlytotheleft.The'h'drawsalinedirectlytotheleftofthescreen.Thesecond''symbolagainturnstheturtle90degreestoitsleftwhichisdirectlydownonthescreen.Thefsymboldrawsaunitlengthlineinthedowndirection.Thelastturnsymbolinthestringisa'+'whichturnstheturtletoitsrightby90degrees.However,sincecurrentheadingoftheturtleispointeddownward,itsrightisthescreen'sleft,soagaintheturtle'sheadingistotheleftofthescreen.Finally,thehsymboldrawsaunitlengthlinetothescreen'sleft.Theresultingimageisshownisfigure1withlinesegmentcolorsmatchingthe'f'and'h'colorsinthedescriptionabove.

    figure1

    FractalGrowerHome

    Copyright:JoelCastellanos,19962007

    http://www.cs.unm.edu/~joel/PaperFoldingFractal/paper.html