ex928(2) - alma = Turtle() alma.up() #alma.setx(-400)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import cTurtle def applyProduction(axiom,rules,n): for i in range(n): newString = "" for ch in axiom: newString = newString + rules.get(ch,ch) axiom = newString return axiom from cTurtle import * def drawLS(aTurtle,instructions,angle,distance): for cmd in instructions: if cmd == 'F': aTurtle.forward(distance) elif cmd == 'B': aTurtle.backward(distance) elif cmd == '+': aTurtle.right(angle) elif cmd == '-': aTurtle.left(angle) else: print('Error: %s is an unknown command'%cmd)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: alma = Turtle() alma.up() #alma.setx(-400) #alma.sety(-200) alma.down() axiom = 'F-F+F+F' rules = { 'F' : 'F+F-F+FF-F+F-F' } #result = applyProduction(axiom, rules, 1) #drawLS(alma, result, 90, 10) #result = applyProduction(axiom, rules, 2) #drawLS(alma, result, 90, 10) #result = applyProduction(axiom, rules, 3) #drawLS(alma, result, 90, 10) result = applyProduction(axiom, rules, 4) drawLS(alma, result, 90, 10)...
View Full Document

This document was uploaded on 12/14/2010.

Ask a homework question - tutors are online