我正在制作一个程序,它使用 pymouse 获取鼠标坐标,然后使用 turtle 在该点上画一个点。
然而, turtle 坐标系和 pymouse 坐标系有很大不同:在 turtle 坐标系中,左边是 0,右边是 1920(对我来说),顶部是 0,底部是 1040(对我来说),但在 turtle 坐标系中系统左为-480,右为480,中为0,上为400,下为-400,中为0。
我使用的是 python 3.6.2,我的操作系统是 Windows 10 32 位
如何将鼠标坐标转换为 turtle 坐标?
请您参考如下方法:
弯曲 turtle 的坐标系以匹配 pymouse 可能是最简单的:
from turtle import Turtle, Screen
screen = Screen()
screen.setup(1920, 1040)
screen.setworldcoordinates(0, 1040, 1920, 0)
yertle = Turtle(visible=False)
yertle.dot(5, 'red') # starts life at (0, 0)
screen.exitonclick()
