daily pastebin goal
67%
SHARE
TWEET

CSH2012 Lsystem.py

calcpage Apr 19th, 2013 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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"))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top