0
私は大きなプログラムのためにPythonでTurtle Graphicsを使用しています。ユーザーがクリックした点をturtle.onscreenclickで返すことができますタートルグラフィックス - オンスクリーンからの色の抽出
ただし、ユーザーがクリックするポイントのRGBカラーを抽出したいと思います。これは亀のグラフィックでもできますし、これをどのように達成できますか?ありがとうございました!
import turtle
# Global variables specifying the point clicked
xclick = 0
yclick = 0
# Draw a rectangle that is red
height = float(50)
length = height *(1.9)
length = round(length,2)
turtle.begin_fill()
turtle.color("red")
turtle.down()
turtle.forward(length)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.forward(length)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.end_fill()
# Gets the click
def getcoordinates():
turtle.onscreenclick(turtle.goto)
turtle.onscreenclick(modifyglobalvariables)
# Modifies the global variables
def modifyglobalvariables(rawx,rawy):
global xclick
global yclick
xclick = int(rawx//1)
yclick = int(rawy//1)
print(xclick)
print(yclick)
getcoordinates()
turtle.done()