Skip to content

Instantly share code, notes, and snippets.

@philipaconrad
Created May 9, 2013 05:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipaconrad/5545823 to your computer and use it in GitHub Desktop.
Save philipaconrad/5545823 to your computer and use it in GitHub Desktop.
A basic algae L-system, as described on http://en.wikipedia.org/wiki/L-System.
# lsystem.py -- simple algae L-System, as described on Wikipedia.
# Copyright (c) Philip Conrad 2013 -- MIT License
def IterSystem(inString):
out = ""
inLen = len(inString)
for i in range(0, inLen):
c = inString[i]
if(c == "A"):
out += "AB"
elif(c == "B"):
out += "A"
else:
print "Error, not in alphabet of this L-System."
return out
if __name__ == '__main__':
start = "A"
inStr = start
for x in range(0, 5):
result = IterSystem(inStr)
print result
inStr = result
print "Done!"
@philipaconrad
Copy link
Author

Verbatim text from the wikipedia article example:


Lindenmayer's original L-system for modelling the growth of algae.

  • variables : A B
  • constants : none
  • start : A
  • rules : (A → AB), (B → A)

which produces:

n = 0 : A
n = 1 : AB
n = 2 : ABA
n = 3 : ABAAB
n = 4 : ABAABABA
n = 5 : ABAABABAABAAB
n = 6 : ABAABABAABAABABAABABA
n = 7 : ABAABABAABAABABAABABAABAABABAABAAB 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment