分形树的绘制

import turtle
def draw_branch(size):
    #右分支
    if(size<5):
        turtle.color('green')
    if(size>=5):
        turtle.forward(size)
        turtle.right(20)
        draw_branch(size-20)

    #左分支
        turtle.left(40)
        draw_branch(size-20)

        turtle.right(20)
        turtle.backward(size)
        turtle.color('brown')

def main():
    turtle.left(90)
    turtle.pensize(5)
    turtle.backward(100)
    draw_branch(100)

if(__name__ =='__main__'):
    main()
    turtle.exitonclick()

 

你可能感兴趣的:(Python基础入门)