Advertisement
jeffwincek

L-Systems 0.0.2

Dec 15th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from turtle import *
  2.  
  3.  
  4. axiomA='A'
  5. rulesA = {}
  6. rulesA['A'] = 'AB'
  7. rulesA['B'] = 'A'
  8.  
  9. axiomB='B'
  10. rulesB = {}
  11. rulesB['B'] = 'BA'
  12. rulesB['A'] = 'B'
  13.  
  14. axiomF='F'
  15. rulesF = {}
  16. rulesF['F'] = 'F+F-F-F+F'
  17.  
  18.  
  19. def compose(axiom, rules):
  20.         output = ""
  21.         for i in axiom:
  22.             output = output + rules.get(i,i)
  23.         return output
  24.  
  25. def iterate(axiom,rules, times):
  26.     output = ''
  27.     if times == 0:
  28.         output = axiom
  29.     else:
  30.         return iterate(compose(axiom, rules), rules, times -1)
  31.     return output
  32.  
  33. print iterate(axiomA,rulesB,6)
  34. print iterate(axiomB,rulesA,6)
  35. directions = iterate(axiomF,rulesF,3)
  36. print directions
  37.  
  38. color('red','yellow')
  39. begin_fill()
  40. for words in directions:
  41.     if words == 'F':
  42.         forward(10)
  43.     elif words == '+':
  44.         left(90)
  45.     elif words == '-':
  46.         right(90)
  47.        
  48. end_fill()
  49. done()
  50.  
  51. #special thanks to http://www.4dsolutions.net/ocn/lsystems.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement