有没有办法让multiple
海龟在same time
移动?(至少看起来是这样)
我正试图在Python 3.4.3
中使用Turtle制作一个"tusi couple"
(如果您不知道它是什么,请查找GIF
)。不过,我不太确定如何让多只海龟在same time.
处移动smoothly
我已经试过让我的乌龟移动了in turn
,而且几乎用我能想到的所有方法,甚至试过合并几个子例程,但是我试过的每件事都会妥协smoothness
或speed
,或者它不起作用
这是我开始使用的initial code
:
import turtle
def dot1():
p1, p2 = turtle.Turtle(), turtle.Turtle()
p1.goto(-300,0) #p = point
p2.goto(300,0)
c1, c2 = p1.position(), p2.position() #c = coordinate
dot = turtle.Turtle()
p1.penup()
p2.penup()
p1.shape("circle")
p2.shape("circle")
dot.shape("circle")
dot.turtlesize(3)
dot.penup()
dot.hideturtle()
dot.goto(c1)
dot.showturtle()
dot.speed(0)
dot.setheading(dot.towards(c2)) #Towards second dot
while dot.distance(c2) > 6:
if dot.distance(c1) <300:
dot.fd((dot.distance(c1)+0.1)/30)
else:
dot.fd(dot.distance(c2)/30)
dot.setheading(dot.towards(c1)) #Towards first dot
while dot.distance(c1) > 6:
if dot.distance(c1) >300:
dot.fd((dot.distance(c2)+0.1)/30)
else:
dot.fd(dot.distance(c1)/30)
dot1()
从这里可以看出我想让这个子程序的multiple copies
运行,但是at different angles
。这些海龟的minimum being 3
。你知道吗
一般来说,我对python还比较陌生,所以如果这是一个需要解决的简单问题,那么请给我一个tip
关于我应该研究的问题,如果解决方案简单/易于理解,那么我不希望entire thing
为我完成。你知道吗
这绝对是一个有趣的挑战,直到我意识到我不知道如何使这项工作。你知道吗
谢谢你的帮助。你知道吗
编辑:如果你看到这个GIF最好:http://intothecontinuum.tumblr.com/post/57654628209/each-of-the-white-circles-are-really-just-moving
Python龟是令人钦佩的没有速度恶魔当谈到动画。要想从中获得任何速度,关键是花时间去理解它是如何工作的,并要求它尽可能少地做。下面是我实现的“每个白圈都在移动”的GIF动画图像:
如果要查看圆在哪些行上来回移动,请在
turtles = []
行之前添加以下代码:相关问题 更多 >
编程相关推荐