Advertisement
calcpage

CSH2012 Lsystem.py

Apr 19th, 2013
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. #!/usr/bin/python
  2. def applyRules(ch):
  3.     newstr = ""
  4.     if ch == 'F':
  5.         newstr = 'F-F++F-F'   # Rule 1
  6.     else:
  7.         newstr = ch    # no rules apply so keep the character
  8.  
  9.     return newstr
  10.  
  11.  
  12. def processString(oldStr):
  13.     newstr = ""
  14.     for ch in oldStr:
  15.         newstr = newstr + applyRules(ch)
  16.  
  17.     return newstr
  18.  
  19.  
  20. def createLSystem(numIters,axiom):
  21.     startString = axiom
  22.     endString = ""
  23.     for i in range(numIters):
  24.         endString = processString(startString)
  25.         startString = endString
  26.  
  27.     return endString
  28.  
  29. print(createLSystem(4,"F"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement