import turtle as tu
roo = tu.Turtle() # 创建对象
wn = tu.Screen() # 屏幕对象
wn.bgcolor("black") # 屏幕背景
wn.title("分形树")
roo.left(90) # 移动
roo.speed(20) # 速度
def draw(l): # 以长度\'l\'作为参数的递归函数
if l < 10:
return
else:
roo.pensize(2) # 设置画笔大小
roo.pencolor("yellow") # 画笔颜色
roo.forward(l) # 朝向
roo.left(30) # 移动
draw(3 * l / 4) # 绘制
roo.right(60) # 移动
draw(3 * l / 4) # 绘制
roo.left(30) # 移动
roo.pensize(2)
roo.backward(l) # 返回初始位置
draw(20) # 绘制20次
roo.right(90)
roo.speed(2000)
# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor("magenta") # magenta
roo.forward(l)
roo.left(30)
draw(3 * l / 4)
roo.right(60)
draw(3 * l / 4)
roo.left(30)
roo.pensize(2)
roo.backward(l)
draw(20)
roo.left(270)
roo.speed(2000)
# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor("red") # red
roo.forward(l)
roo.left(30)
draw(3 * l / 4)
roo.right(60)
draw(3 * l / 4)
roo.left(30)
roo.pensize(2)
roo.backward(l)
draw(20)
roo.right(90)
roo.speed(2000)
# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(2)
roo.pencolor(\'#FFF8DC\') # white
roo.forward(l)
roo.left(30)
draw(3 * l / 4)
roo.right(60)
draw(3 * l / 4)
roo.left(30)
roo.pensize(2)
roo.backward(l)
draw(20)
########################################################
def draw(l):
if (l < 10):
return
else:
roo.pensize(3)
roo.pencolor("lightgreen") # lightgreen
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)
draw(40)
roo.right(90)
roo.speed(2000)
# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(3)
roo.pencolor("red") # red
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)
draw(40)
roo.left(270)
roo.speed(2000)
# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(3)
roo.pencolor("yellow") # yellow
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)
draw(40)
roo.right(90)
roo.speed(2000)
# recursion
def draw(l):
if (l < 10):
return
else:
roo.pensize(3)
roo.pencolor(\'#FFF8DC\') # white
roo.forward(l)
roo.left(30)
draw(4 * l / 5)
roo.right(60)
draw(4 * l / 5)
roo.left(30)
roo.pensize(3)
roo.backward(l)
draw(40)