运行效果
代码
import turtle as t
import random as r
c = ["pink", "green", "lightgreen", "orange", "red", "purple"]
def drawStar(l):
t.begin_fill()
for i in range(5):
t.forward(l)
t.left(144)
t.end_fill()
def drawBranch(l):
agl = r.randint(10, 30)
t.left(agl)
t.forward(l)
if l > 10:
drawBranch(l - r.randint(10, 15))
else:
t.pencolor(r.choice(c))
drawStar(r.randint(10, 20))
t.pencolor("black")
t.backward(l)
t.right(agl)
agl = r.randint(10, 30)
t.right(agl)
t.forward(l)
if l > 10:
drawBranch(l - r.randint(10, 15))
else:
t.pencolor(r.choice(c))
drawStar(r.randint(10, 20))
t.pencolor("black")
t.backward(l)
t.left(agl)
# t.speed(0)
t.tracer(False)
t.penup()
t.goto(0,-300)
t.pendown()
t.left(90)
t.forward(50)
drawBranch(100)
t.done()
标签:turtle,10,agl,递归,randint,python,pencolor,drawBranch,forward
From: https://www.cnblogs.com/AaronMing/p/18011981