Hello all, first post here so hopefully this is in the right place.
Would be greatful iff someone could help me understand something, Im just starting to
learn python as a hobbyist and was doing some fractal tutorials with Turtle.
Came across code for a fractal tree, as bellow.
I was expecting the programme to draw one y fork, then another smaller y fork comming from the left of the first and so on till x hits 5.
So i guss my question is why does python draw a single line always executing the left turn untill x hits its < cut off, instead of going through all of the commands within the else loop first?
I hope that makes sense?
Would be greatful iff someone could help me understand something, Im just starting to
learn python as a hobbyist and was doing some fractal tutorials with Turtle.
Came across code for a fractal tree, as bellow.
import turtle
PROGNAME = 'Fractal Tree'
myPen = turtle.Turtle()
myPen.up()
myPen.left(90)
myPen.back(300)
myPen.down()
myPen.speed(10)
myPen.color("#000000")
#Recursive draw, where x is length
def draw(x):
if(x<5):
return
else:
myPen.forward(x)
myPen.left(30)
draw(3*x/4)
myPen.right(60)
draw(3*x/4)
myPen.left(30)
myPen.back(x)
# call draw
draw(300)Now I thought I understood all this untill noticing when running the programme that turtle always draws the left track untill x hits 5, then traces back and does the next left turn till again x hits 5.I was expecting the programme to draw one y fork, then another smaller y fork comming from the left of the first and so on till x hits 5.
So i guss my question is why does python draw a single line always executing the left turn untill x hits its < cut off, instead of going through all of the commands within the else loop first?
I hope that makes sense?
