我有一个任务要求在赛道上设置两只乌龟(相同大小但不同的赛道)。我可以让它们移动,但只有当第一个移动了一半的轨道时,第二个才会移动。我不知道如何让乌龟同时移动。这是我的代码:
import turtle
import random
import time
wn = turtle.Screen()
wn.bgcolor("lightgreen")
t = turtle.Turtle()
t.shape('turtle')
t.color('red')
t2 = turtle.Turtle()
t2.shape('turtle')
t2.color('blue')
#user input function
p = float(input('please insert the perimeter:'))
#set the track
def drawTrack(p,r):
shortside = (p/2.0)/(r+1)
longside = r*shortside
turtle.setup((shortside*2)+60, longside +40)
t.penup()
t2.penup()
t.setposition(-shortside-10, -longside/2)
t2.setposition(10, -longside/2)
for i in range (2):
#first track
t.speed(1)
t.pendown()
t.forward(shortside)
t.left(90)
t.forward(longside)
t.left(90)
#second track
t2.speed(1)
t2.pendown()
t2.forward(shortside)
t2.left(90)
t2.forward(longside)
t2.left(90)
drawTrack(p,2)
wn.exitonclick()