Commit 68718fa5 by BellCodeEditor

auto save

parent 5deea2f0
Showing with 25 additions and 11 deletions
import turtle # 导入turtle模块
import random # 导入random模块
pen = turtle.Turtle() # 创建画笔
pen.color('sienna') # 设置画笔颜色
pen.speed(0)
# 画布大小
w = turtle.Screen()
w.bgcolor('wheat') # 设置画布颜色wheat小麦
......@@ -11,18 +13,30 @@ pen.up() # 抬笔
pen.backward(150) # 后退150
pen.down() # 落笔
# 分形
# 樱花
def tree(n) : # def定义tree()函数参数为n
if n >= 50: # if判段变量n>=50
if n >= 0: # if判段变量n>=0
if n <= 12: # if判断变量n<=12
# 建立列表color_list,索引0为'snow'索引1为'lightcoral'
color_list = ['snow', 'lightcoral']
# 用random.choice()方法参数为color_list并赋值给变量color_list
color = random.choice(color_list)
pen.color(color) # 用pen.color()方法参数为color
pen.pensize(n / 3) # 用pen.pensize()方法参数为n / 3
else: # 否则
pen.color('sienna') # 赭(zhe)色
pen.pensize(n / 10) # 用pen.pensize()方法参数为n / 10
pen.forward(n) # 前进变量n
pen.right(30) # 右转30
tree(n-10) # 函数tree()的值设为n-50
pen.left(60) # 左转60
tree(n-10) # 函数tree()的值设为n-50
pen.right(30) # 右转30
angle = random.random() # 用random.random()方法并赋值给变量angle
pen.right(30*angle) # 右转30乘angle
length = 1.5*random.random() # 用random.random()方法*1.5 并赋值给变量length
tree(n-10*length) # 函数tree()的值设为n-10*length
pen.left(60*angle) # 左转60*angle
tree(n-10*length) # 函数tree()的值设为n-10*length
pen.right(30*angle) # 右转30*angle
pen.up() # 抬笔
pen.backward(n) # 用backward()方法n
pen.down() # 用down()方法落笔
pen.backward(n) # 用backward()方法后退变量n
pen.down() # 落笔
tree(100) # tree()方法参数设为100
turtle.done()
tree(60) # 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