python递归程序画图:
https://python123.io/index/turtles/5e3a9694883dab383425d574
截图:
代码:
#20200731 程序猿
# python 递归画图
import turtle
SIZE_TREE = 40
def draw_tree(size):
if size > SIZE_TREE:
# 给最后的树枝画绿色
turtle.pendown()
if size <=50:
turtle.color('green')
else:
turtle.color('brown')
turtle.forward(size)
# 右边
turtle.right(20)
draw_tree(size -5)
# 左边
turtle.left(40)
draw_tree(size -5)
# 抬笔,回到之前的树枝
turtle.right(20)
turtle.penup()
turtle.backward(size)
def main():
turtle.speed(2)
turtle.hideturtle()
turtle.penup()
# 方向向上
turtle.left(90)
turtle.backward(100)
turtle.showturtle()
# 画笔隐形
# 画笔有效
turtle.pendown()
turtle.pensize(2)
turtle.color('brown')
# 给出根的长度
draw_tree(60)
main()