import turtle
这里的 turtle 绘画库
https://www.cnblogs.com/kwkk978113/p/10307013.html
def draw_brach(brach_length):
""" 递归函数进行画分形树 """
if brach_length > 5:
turtle.pencolor("brown")
turtle.pensize(3)
turtle.forward(brach_length)
turtle.right(30)
draw_brach(brach_length - 15)
turtle.left(60)
draw_brach(brach_length - 15)
turtle.right(30)
turtle.up()
turtle.backward(brach_length)
turtle.down()
if brach_length<=10:
turtle.pencolor("green")
turtle.pensize(5)
turtle.forward(brach_length)
turtle.right(30)
draw_brach(brach_length - 15)
turtle.left(60)
draw_brach(brach_length - 15)
turtle.right(30)
turtle.up()
turtle.backward(brach_length)
turtle.down()
def main():
turtle.speed(100)
turtle.left(90)
turtle.up()
turtle.backward(200)
turtle.down()
turtle.pensize(10)
draw_brach(100)
turtle.exitonclick()
if __name__ == '__main__':
main()