Commit a78edcb4 by BellCodeEditor

save project

parent 576b5884
Showing with 41 additions and 0 deletions
import turtle
import random
pen = turtle.Turtle()
pen.color('sienna')
pen.speed(0)
# 画布大小
w = turtle.Screen()
w.bgcolor('wheat') # wheat小麦
def tree(n):
if n>=0:
angle=random.randint(15,30)
lenth=random.randint(1,25)
pencolor=['snow','lightcoral']
tree_lenth=n-lenth
if tree_lenth<5:
pen.color(random.choice(pencolor))
pen.pensize(3)
else:
pen.pensize(n/10)
pen.color('sienna')
pen.forward(n) #树干
pen.right(angle) #右边树干
tree(tree_lenth) #右边树枝
pen.left(2*angle) #左边树枝
tree(tree_lenth) #左边树枝
pen.right(angle) #返回起点
pen.up() #退回起点
pen.backward(n) #退回起点
pen.down() #退回起点
# 移动到起点
pen.left(90)
pen.up()
pen.backward(150) # 后退
pen.down()
tree(100)
turtle.done()
\ No newline at end of file
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