我想在python中創建一個分形樹。我已經制作了樹,但我想要有2只或更多的海龜來一次繪製我的分形樹。有沒有辦法做到這一點?我尋找解決方案,但沒有一個是我真正想要的。這裏是我的代碼:如何在Python3中一次移動2個海龜
import turtle
tree = turtle.Turtle()
tree.ht()
tree.penup()
tree.sety(-200)
tree.left(90)
import turtle
tree0 = turtle.Turtle()
tree0.ht()
tree0.penup()
tree0.sety(-200)
tree0.left(90)
startx = tree.xcor()
starty = tree.ycor()
startx = tree0.xcor()
starty = tree0.ycor()
def fractalright(angle, length, x, y):
tree.speed(0)
tree.setx(x)
tree.sety(y)
tree.pendown()
tree.forward(length)
tree.right(angle)
length = length - 20
x = tree.xcor()
y = tree.ycor()
if length < 0:
return
tree.penup()
fractalright(angle, length, x, y)
tree.penup()
tree.setx(x)
tree.sety(y)
tree.left(angle)
fractalright (-angle, length, x, y)
def fractalleft(angle, length, x, y):
tree0.speed(0)
tree0.setx(x)
tree0.sety(y)
tree0.pendown()
tree0.forward(length)
tree0.right(angle)
length = length - 20
x = tree0.xcor()
y = tree0.ycor()
if length < 0:
return
tree0.penup()
fractalleft(angle, length, x, y)
tree0.penup()
tree0.setx(x)
tree0.sety(y)
tree0.left(angle)
fractalleft (-angle, length, x, y)
我使用python 3,請讓我知道如果你知道一個解決方案。謝謝!!
你提到了[multiprocessing](https://docs.python.org/2/library/multiprocessing.html),你看過那個文檔,另一個選項是[threading](https:/ /docs.python.org/2/library/threading.html),我會建議看看他們,然後嘗試一個,然後如果你仍然有問題回來這些。 –