Commit a33b558f by BellCodeEditor

save project

parent 576b5884
Showing with 46 additions and 0 deletions
import turtle
import random
angle=random.randint(15,30)
lenth=random.randint(1,15)
pencolor=["snow","lightcoral"]
pen = turtle.Turtle()
pen.color('sienna')
pen.speed(0)
# 画布大小
w = turtle.Screen()
w.bgcolor('wheat') # wheat小麦
pen.pensize(5)
def tree(n):
if n>=0:
angle=random.randint(15,30)
lenth=random.randint(1,15)
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(80)
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