Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获得python中一组坐标处的颜色?_Python_Python Turtle - Fatal编程技术网

如何获得python中一组坐标处的颜色?

如何获得python中一组坐标处的颜色?,python,python-turtle,Python,Python Turtle,在python中,我试图创建一个函数来获取海龟当前所处的颜色。我发现turtle.pos()给了我它的位置坐标,我如何使用这些坐标来获得颜色?我认为最好的方法是使用这里显示的步骤:一种方法是将你创建的每一只海龟添加到一个列表中,然后在你的主游戏循环中,循环查看海龟列表,查看turtle.distance()是否小于某个值: import turtle wn = turtle.Screen() turtles = [] yertle = turtle.Turtle('turtle') whi

在python中,我试图创建一个函数来获取海龟当前所处的颜色。我发现turtle.pos()给了我它的位置坐标,我如何使用这些坐标来获得颜色?

我认为最好的方法是使用这里显示的步骤:

一种方法是将你创建的每一只海龟添加到一个列表中,然后在你的主游戏循环中,循环查看海龟列表,查看
turtle.distance()
是否小于某个值:

import turtle

wn = turtle.Screen()
turtles = []

yertle = turtle.Turtle('turtle')

while True:
    wn.tracer(0)
    for t in turtles:
        if yertle.distance(t) < 20 and yertle != t:
            print(f'Touched {t.color()}')
    wn.update()
导入海龟
wn=tutle.Screen()
海龟=[]
耶特尔=乌龟。乌龟(“乌龟”)
尽管如此:
wn.tracer(0)
对于海龟中的t:
如果耶特尔距离(t)<20且耶特尔!=t:
打印(f'toucted{t.color()}')
wn.update()
在上面的代码中,我使用了
if yertle.distance(t)<20
,这是当所有海龟都是默认大小时使用的:
20