Example #1
0
def interpret_Lsytem(path, forward=7, angle=60, filename='', ignore = None):
    """
    @param turtle The turtle to guide
    @param dist   Distance to be made with each 'forward'
    @param angle  Angle for 'left' and 'right'
    """
    turtle = Turtle(filename)
    turtle.left(180)

    if ignore == None: ignore = []
    stack = []

    for c in path:
        if c == '+':
            turtle.right(angle)
        elif c == '-':
            turtle.left(angle)
        elif c == '[':
            stack.append(turtle.serialize())
        elif c == ']':
            turtle.deserialize(stack.pop())
        elif c not in ignore:
            turtle.forward(forward)

    if filename:
        turtle.save()

    return
Example #2
0
def interpret_Lsytem2(path, forward=7, angle=60, filename=''):
# goes through the path and draws 

    turtle = Turtle(filename)
    turtle.left(90)
    states = []
    instr  = { 'A' : ['forward', forward],
               'F' : ['forward', forward],
               'B' : ['forward', forward],
               'x' : ['forward', 0],
               'y' : ['forward', 0],
               '-' : ['left', angle],
               '+' : ['right', angle]}

    for step in path:
        if step == '[':
            states.append(turtle.serialize())
        elif step == ']':
            #state = states.pop()
            turtle.deserialize(states.pop())
        else:
            getattr(turtle, instr[step][0])( instr[step][1])

    if filename:
        turtle.save()

    return