Commit 39f6bfa9 by BellCodeEditor

save project

parent 576b5884
Showing with 40 additions and 0 deletions
import turtle
from random import randint,choice
colors=['red','sienna','white']
def tree(n,l=50):
pen.pensize(randint(3,5))
pen.pencolor(choice(colors))
if n>1:
pen.down()
a=randint(5,50)
pen.right(a)
pen.forward(l)
pen.up()
tree(n-1,l*(randint(50,100)/100))
pen.forward(-l)
b=randint(35,60)
pen.left(b)
pen.down()
pen.forward(l)
pen.up()
tree(n-1,l*(randint(50,100)/100))
pen.forward(-l)
pen.right(b-a)
pen = turtle.Turtle()
pen.color('sienna')
# 画布大小
w = turtle.Screen()
w.bgcolor('wheat') # wheat小麦
pen.pensize(10)
# 移动到起点
pen.left(90)
pen.up()
pen.backward(150) # 后退
pen.down()
pen.forward(100)
tree(7)
pen.forward(-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