Reputation: 123
This is my first time ever using turtle, so bear with me. I am suppose to make a tree diagram in python using turtle. I made the tree and it looks perfect except for one problem, which might seem really simple but, when I print out my tree it looks like this.
So what would I add to make my tree right side up? Here is my code. Thanks in advance!
import turtle
t = turtle.Turtle()
def tree(length = 100):
if length < 10:
return
t.forward(length)
t.left(30)
tree(length *.7)
t.right(60)
tree(length * .7)
t.left(30)
t.backward(length)
return
tree()
turtle.done()
Upvotes: 0
Views: 1742
Reputation: 16711
You must remember that the function is recursive, thus you need to turn the turtle outside of the function. You can use a function in a function, but I would just turn the turtle in the global scope right before you call the function:
t.left(90) # then call tree after with tree()
Upvotes: 1