Mar-14-2020, 10:46 AM
Mar-14-2020, 10:54 AM
Define "axiom" in this context. Also, what have you tried, or looked up or anything? We aren't here to do the work for you.
Mar-15-2020, 12:02 PM
Hello, thank you for your reply.
sorry about that. I forgot to show what I've worked. So this is what I've worked :
[python]
for i in range(len(axiom)):
c = axiom[i]
if c == 'F':
alex.forward(l)
if c == '-':
alex.left(d)
if c == '+':
alex.right(d)
if c == '[':
stack.append((alex.heading(), alex.pos()))
if c == ']':
heading, position = stack.pop()
alex.penup()
alex.goto(position)
alex.setheading(heading)
alex.pendown()
[\pyhton]
as the rule will produce this image
https://mail.google.com/mail/u/0?ui=2&ik..._k7szjeoz1
So now my lecturer told me to find the axiom of those pictures by applying the same rule.
Thanks you. Sorry for my bad english.
sorry about that. I forgot to show what I've worked. So this is what I've worked :
import turtle D = 90 L = 10 def iterate(axiom, num=0, initator='F'): """ Compute turtle rule string by iterating on an axiom """ def translate(current, axiom): """ Translate all the "F" with the axiom for current string """ result = '' consts = {'+', '-', '[', ']'} for c in current: if c in consts: result += c continue if c == 'F': result += axiom return result # Set initator result = initator for i in range(0, num): # For ever iteration, translate the rule string result = translate(result, axiom) return result def draw(axiom, d=D, l=L): """ Use turtle to draw the L-System """ stack = [] # For tracking turtle positions screen = turtle.Screen() screen.bgcolor('black') screen.setup(width=1000,height=1000,startx = 500,starty=0) alex = turtle.Turtle() alex.pencolor('yellow') alex.up() alex.left(90) alex.setposition(0,-250) alex.down() alex.hideturtle() alex.speed(1) for i in range(len(axiom)): c = axiom[i] if c == 'F': alex.forward(l) if c == '-': alex.left(d) if c == '+': alex.right(d) if c == '[': stack.append((alex.heading(), alex.pos())) if c == ']': heading, position = stack.pop() alex.penup() alex.goto(position) alex.setheading(heading) alex.pendown() if __name__ == '__main__': axiom = "FF-[-F+F+F]+[+F-F-F]" axiom = iterate(axiom, 5, "F") draw(axiom, 25, 13)So using the FF-[-F+F+F]+[+F-F-F] as the axiom and using:
[python]
for i in range(len(axiom)):
c = axiom[i]
if c == 'F':
alex.forward(l)
if c == '-':
alex.left(d)
if c == '+':
alex.right(d)
if c == '[':
stack.append((alex.heading(), alex.pos()))
if c == ']':
heading, position = stack.pop()
alex.penup()
alex.goto(position)
alex.setheading(heading)
alex.pendown()
[\pyhton]
as the rule will produce this image
https://mail.google.com/mail/u/0?ui=2&ik..._k7szjeoz1
So now my lecturer told me to find the axiom of those pictures by applying the same rule.
Thanks you. Sorry for my bad english.