【发布时间】:2019-07-25 07:27:47
【问题描述】:
我试图让乌龟形状跟随一条线的方向。
我有一个简单的抛物线,我希望乌龟形状跟随直线的方向 - 当图形上升时,乌龟面朝上,当图形下降时,乌龟面朝下。
我使用goto() 作为海龟的位置,x=x+1 作为图表上的 x 位置:
t.goto(x,y)
t.right(??) - this?
t.left(??) - this?
t.setheading(??) or this?
实现这一目标的最佳方法是什么?当我尝试在 while 循环中使用 t.right() 时(我一直在循环直到 x 完成),海龟在移动时继续旋转一圈,这 不是 我想要的。
仍然没有得到这个。我添加了建议的额外代码 - 这是我想要实现的编辑和完整代码......
我正在使用轨迹的物理公式(我使用了这个,所以我知道我输出的值是正确的)。 http://www.softschools.com/formulas/physics/trajectory_formula/162/
import math
import turtle
import time
w=turtle.Turtle()
i=0
angle=66.4
velocity=45.0
g=9.8
t=math.tan(math.radians(angle))
c=math.cos(math.radians(angle))
turtle.delay(9)
w.shape("turtle")
w.setheading(90)
while i < 150:
start = i * t
middle = g*(i**2)
bottom =(2*(velocity**2)*c**2)
total = start-middle/bottom
print(total)
w.setheading(turtle.towards(i,total))
w.goto(i,total)
i=i+1
turtle.exitonclick()
【问题讨论】:
-
你能看看我为这个问题编辑的代码吗?
标签: python graphics turtle-graphics