如果您运行以下代码,它会创建我正在尝试创建的两个并排图。我需要弄清楚如何在第一次绘制递归方法后停止它。
import turtle
def drawTriangle(size):
turtle.left(30)
turtle.forward(size)
turtle.right(120)
turtle.forward(size)
turtle.right(120)
turtle.forward(size)
turtle.right(120)
turtle.up()
turtle.forward(size)
turtle.right(30)
turtle.down()
def drawTriangles(size, depth):
if (depth < 1):
pass
else:
drawTriangle(size)
drawTriangles(size / 2, depth - 1)
turtle.up()
turtle.left(30)
turtle.forward(-size)
turtle.right(120)
turtle.forward(size * 2)
turtle.left(90)
turtle.down()
drawTriangle(size)
drawTriangles(size / 2, depth - 1)
turtle.up()
turtle.left(30)
turtle.forward(-size)
turtle.left(60)
turtle.forward(size * 2)
turtle.right(90)
turtle.down()
turtle.home()
turtle.left(90)
turtle.down()
turtle.speed("normal")
drawTriangles(100, 4)
input("pause")