python,递归函数画树,海龟作图,turtle
import turtle import time def tree(t,trunk_length, pensize): if trunk_length > 5: t.pensize(pensize) t.forward(trunk_length) t.right(20) tree(t,trunk_length-5,pensize-1) t.left(40) tree(t,trunk_length-5,pensize-1) if trunk_length - 5 <= 5: t.pencolor('green') t.circle(2) t.pencolor('purple') t.right(20) t.backward(trunk_length) t = turtle.Turtle() trunk_length = 40 pensize = 8 t.pencolor('purple') angle = 20 t.left(90) tree(t, trunk_length, pensize) time.sleep(40)