Python,移动海龟到相对坐标

1 投票
2 回答
10286 浏览
提问于 2025-04-18 03:22

我在Python的文档或者这里找不到相关内容。 这是个很简单的问题,我想知道怎么让我的海龟在x轴上移动-15,在y轴上也移动-15。也就是说,我不想直接去某个具体的位置,而是想相对地移动-15个单位。 我只找到怎么移动到绝对位置的方法,有没有其他的解决办法呢?

2 个回答

0
import turtle

shelly = turtle.Turtle()

def relative_move(x=None, y=None):

    if x is not None:
        shelly.setx(shelly.xcor() + x)

    if y is not None:
        shelly.setx(shelly.ycor() + y)

relative_move(x=15)
relative_move(x=-10)

print shelly.xcor() #should be 5

当然可以!请把你想要翻译的内容发给我,我会帮你用简单易懂的语言解释清楚。

8

简单来说,就是获取当前位置,修改它,然后移动到那个位置。

turtle.goto( turtle.pos() + (15,-15) )

撰写回答