Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import *
- axiomA='A'
- rulesA = {}
- rulesA['A'] = 'AB'
- rulesA['B'] = 'A'
- axiomB='B'
- rulesB = {}
- rulesB['B'] = 'BA'
- rulesB['A'] = 'B'
- axiomF='F'
- rulesF = {}
- rulesF['F'] = 'F+F-F-F+F'
- def compose(axiom, rules):
- output = ""
- for i in axiom:
- output = output + rules.get(i,i)
- return output
- def iterate(axiom,rules, times):
- output = ''
- if times == 0:
- output = axiom
- else:
- return iterate(compose(axiom, rules), rules, times -1)
- return output
- print iterate(axiomA,rulesB,6)
- print iterate(axiomB,rulesA,6)
- directions = iterate(axiomF,rulesF,3)
- print directions
- color('red','yellow')
- begin_fill()
- for words in directions:
- if words == 'F':
- forward(10)
- elif words == '+':
- left(90)
- elif words == '-':
- right(90)
- end_fill()
- done()
- #special thanks to http://www.4dsolutions.net/ocn/lsystems.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement