• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# L-Systems 0.0.4

jeffwincek Dec 15th, 2011 37 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. turtleRulesF = {}
18. turtleRulesF['F'] = 'forward(10)'
19. turtleRulesF['+'] = 'left(90)'
20. turtleRulesF['-'] = 'right(90)'
21.
22. axiomS='A'
23. rulesS = {}
24. rulesS['A'] = 'B-A-B'
25. rulesS['B'] = 'A+B+A'
26. turtleRulesS = {}
27. turtleRulesS['A'] = 'forward(3)'
28. turtleRulesS['B'] = 'forward(3)'
29. turtleRulesS['+'] = 'left(60)'
30. turtleRulesS['-'] = 'right(60)'
31.
32. axiomD='FX'
33. rulesD={}
34. rulesD['X']='X+YF'
35. rulesD['Y']='FX-Y'
36. turtleRulesD={}
37. turtleRulesD['F'] = 'forward(5)'
38. turtleRulesD['-'] = 'left(90)'
39. turtleRulesD['+'] = 'right(90)'
40. turtleRulesD['X'] = 'nul'
41. turtleRulesD['Y'] = 'nul'
42.
43.
44. def compose(axiom, rules):
45.         output = ""
46.         for i in axiom:
47.             output = output + rules.get(i,i)
48.         return output
49.
50. def iterate(axiom,rules, times):
51.     output = ''
52.     if times == 0:
53.         output = axiom
54.     else:
55.         return iterate(compose(axiom, rules), rules, times -1)
56.     return output
57.
58. #print iterate(axiomA,rulesB,6)
59. #print iterate(axiomB,rulesA,6)
60. #directions = iterate(axiomF,rulesF,3)
61. #print directions
62.
63. def evaluate(axiom,rules,turtleRules,times):
64.     for words in iterate(axiom,rules,times):
65.         if turtleRules[words] != 'nul':
66.             eval(turtleRules[words])
67. screensize(800,800)
68. speed(0)
69. pu()
70. #setx(-400)
71. #sety(-400)
72. pd()
73. color('red','yellow')
74. #begin_fill()
75. #evaluate(axiomS,rulesS,turtleRulesS,6)
76. evaluate(axiomD,rulesD,turtleRulesD,10)
77. #end_fill()
78. done()
79.
80. #special thanks to http://www.4dsolutions.net/ocn/lsystems.html
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.

Top