Upload
zainul-anwar
View
216
Download
0
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