Save turtle state?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allen

    Save turtle state?

    I'm using the turtle module in Python. Is there a way to save the turle
    state at any moment for recursive algorithms to easily return the turtle
    to an earlier point for another branch/etc?

    Brian Vanderburg II
  • Peter Otten

    #2
    Re: Save turtle state?

    Allen wrote:
    I'm using the turtle module in Python. Is there a way to save the turle
    state at any moment for recursive algorithms to easily return the turtle
    to an earlier point for another branch/etc?
    Just copying the turtle seems to work:

    import turtle
    from copy import copy
    def rec(t, n):
    t.forward(n)
    n = (n*4)/5
    u = copy(t)
    u.color("red")
    u.right(45)
    if n 10:
    rec(u, n)

    def main():
    t = turtle.Turtle()
    t.color("green" )
    for i in range(12):
    t.left(30)
    rec(t, 50)

    main()
    raw_input()

    Peter

    Comment

    Working...