By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,173 Members | 1,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,173 IT Pros & Developers. It's quick & easy.

Save turtle state?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.