Commit a0f2bfa6 by BellCodeEditor

auto save

parent ac0b9721
Showing with 18 additions and 8 deletions
import turtle
import random
pen = turtle.Turtle()
pen.color('sienna')
# 画布大小
w = turtle.Screen()
w.bgcolor('wheat') # wheat小麦
color=["white",'lightcoral']
# 移动到起点
pen.left(90)
......@@ -12,16 +14,24 @@ pen.up()
pen.backward(150) # 后退
pen.down()
def tree(n):
if n >= 50:
if n >= 0:
pen.pensize(n/10)
if n <= 9:
c = random.randint(0,1)
pen.pencolor(color[c])
pen.pensize(n/3)
else:
pen.pencolor('sienna')
pen.forward(n)
pen.right(30)
tree(n-10)
pen.left(60)
tree(n-10)
a = random.randint(0,30)
l = random.randint(1,15)
pen.right(a)
tree(n-l)
pen.left(2*a)
tree(n-l)
pen.penup()
pen.right(30)
pen.right(a)
pen.backward(n)
pen.pendown()
tree(100)
tree(50)
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