Commit e67fa28f by BellCodeEditor

save project

parent 576b5884
Showing with 58 additions and 0 deletions
import turtle
import random
pen = turtle.Turtle()
pen.color('sienna')
# 画布大小
w = turtle.Screen()
w.bgcolor('wheat') # wheat小麦
pen.speed(0)
def tree(n):
if n>=0:
angle = random.randint(15,30)
lenth = random.randint(5,10)
pencolor = ['snow','lightcoral']
tree_lenth = n - lenth
if tree_lenth <5:
pen.color(random.choice(pencolor))
pen.pensize(5)
else:
pen.color('sienna')
pen.pensize(n/10)
pen.fd(n)
pen.right(angle)
tree(tree_lenth)
pen.left(2*angle)
tree(tree_lenth)
pen.right(angle)
pen.up()
pen.bk(n)
pen.down()
# 移动到起点
pen.left(90)
pen.up()
pen.backward(150) # 后退
pen.down()
# pen.fd(100)
# pen.right(30)
# pen.fd(50)
# pen.up()
# pen.bk(50)
# pen.down()
# pen.left(60)
# pen.right(30)
# pen.up()
# pen.bk(100)
# pen.down()
tree(60)
turtle.done()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment