龟图中的乌龟方向?

时间:2017-12-16 00:14:49

标签: python turtle-graphics

如何告诉乌龟面对龟图中的方向? 我希望乌龟转向并面向一个方向,无论它的原始位置如何,我怎么能实现这个目标呢?

6 个答案:

答案 0 :(得分:3)

我认为turtle.setheading() AKA seth()是您正在寻找的功能,所以如果您希望它指向北方:

turtle.setheading(0)

turtle.setheading(90)

取决于您是否符合标准'或者' logo'模式。

正如评论中所指出的,您可以找到此信息here

答案 1 :(得分:0)

setheading命令将是这样做的方式。

turtle.setheading(<degrees/radians>)

是您将如何使用它。在不更改设置的情况下,您将进入标准模式,因此

turtle.setheading(0)

会正确面对乌龟

turtle.setheading(90)

会让乌龟站起来,

turtle.setheading(180)

要面对乌龟,并且

turtle.setheading(270)

会让海龟朝下。希望这会有所帮助!

答案 2 :(得分:0)

或者如果您打算将海龟移到某个位置(x,y)并且想要先将海龟指向那里,则可以使用:

turtle.setheading(turtle.towards(x,y))

答案 3 :(得分:0)

这是我用于游戏的内容:

#Functions
def go_up():
    head.direction="up"

def go_down():
    head.direction="down"

def go_left():
    head.direction="left"

def go_right():
    head.direction="right"


def move():
    if head.direction == "up":
        y = head.ycor()
        head.sety(y + 20)

    if head.direction == "down":
        y = head.ycor()
        head.sety(y - 20)

    if head.direction == "left":
        x = head.xcor()
        head.setx(x - 20)

    if head.direction == "right":
        x = head.xcor()
        head.setx(x + 20)

# Keyboard
win.listen()
win.onkeypress(go_up, "Up")
win.onkeypress(go_down, "Down")
win.onkeypress(go_left, "Left")
win.onkeypress(go_right, "Right")

我希望这会有所帮助

答案 4 :(得分:0)

您可以使用: turtle.right(angle) 要么: turtle.left(angle)。 希望这会有所帮助!

答案 5 :(得分:0)

无论在哪里旋转角度,都可以使用

turtle.setheading()

并将您的角度(转弯方向)放在括号中。