467,105 Members | 1,018 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,105 developers. It's quick & easy.

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
Jun 27 '08 #1
  • viewed: 1749
Share:
1 Reply
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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by dbrown2@yahoo.com | last post: by
4 posts views Thread by Brent W. Hughes | last post: by
1 post views Thread by Irene | last post: by
10 posts views Thread by JulianP | last post: by
7 posts views Thread by Dick Moores | last post: by
5 posts views Thread by tomy | last post: by
4 posts views Thread by hello123 | last post: by
1 post views Thread by Alexander.Oot@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.