Created
May 9, 2013 05:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Verbatim text from the wikipedia article example:
Lindenmayer's original L-system for modelling the growth of algae.
which produces: