My goal is to draw, with the python turtle, a binary tree, in the sense that each line branches into 2, and each of those branches into another two, etc, going from left to right, looking like , except from left to right horizontally. Here's what i have until now, and it works, but if you run it you quickly realise that it's messed up in a lot of ways.
def tree(d,x1,y1):
#d is the depth
if d==0: #base case
return 0
a = t.Turtle()
b = t.Turtle()
t.penup()
a.goto(x1,y1)
b.goto(x1,y1) # move to the correct position
t.pendown()
a.left(30)
b.right(30)
a.forward(50)
b.forward(50)
ax,ay = a.pos() #get position of new turtles
bx,by = b.pos()
input() # Debug ( PRESS ENTER FOR EACH LOOP)
tree(d-1,ax,ay) #recurse top branch
tree(d-1,bx,by) #recurse bottom branch
tree(3,0,0)
Can someone tell me what's wrong and maybe how to fix it? I can tell the angles need to change, but I don't know what to.
