• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# L-Systems 0.0.3

jeffwincek Dec 15th, 2011 29 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(5)'
28. turtleRulesS['B'] = 'forward(5)'
29. turtleRulesS['+'] = 'left(60)'
30. turtleRulesS['-'] = 'right(60)'
31.
32.
33.
34. def compose(axiom, rules):
35.         output = ""
36.         for i in axiom:
37.             output = output + rules.get(i,i)
38.         return output
39.
40. def iterate(axiom,rules, times):
41.     output = ''
42.     if times == 0:
43.         output = axiom
44.     else:
45.         return iterate(compose(axiom, rules), rules, times -1)
46.     return output
47.
48. #print iterate(axiomA,rulesB,6)
49. #print iterate(axiomB,rulesA,6)
50. #directions = iterate(axiomF,rulesF,3)
51. #print directions
52.
53. def evaluate(axiom,rules,turtleRules,times):
54.     for words in iterate(axiom,rules,times):
55.         eval(turtleRules[words])
56.
57. speed(0)
58. setx(-200)
59. color('red','yellow')
60. begin_fill()
61. evaluate(axiomS,rulesS,turtleRulesS,6)
62. end_fill()
63. done()
64.
65. #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