Python and Turtle Difficulty Level 6,recursion Slanted Fractal Tree 2 (Source Code)

Slanted Fractal Tree 2 (Source Code)

Slightly modify the slanted fractal tree to make the color of the branch lighter as the branch gets thinner. Also slightly modify the slant angles.

Slanted Fractal Tree 2

Source Code:

import turtle

screen = turtle.Screen()
screen.title('Slanted Fractal Tree - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
screen.tracer(0,0)
turtle.speed(0)
turtle.hideturtle()

def slanted_tree(x,y,length,direction):
    if length < 2: return
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    turtle.seth(direction)
    turtle.pensize(length/50)
    turtle.color((0.5-length/L*0.5,0.5-length/L*0.5,0.5-length/L*0.5))
    turtle.fd(length)
    px,py = turtle.xcor(), turtle.ycor()
    slanted_tree(px,py,length*0.7,direction+60)
    slanted_tree(px,py,length*0.7,direction-30)

L=400
slanted_tree(100,-500,L,90)
screen.update()

Related Post