Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

python - Turtle graphics color detection

Is there any way to detect the color that the turtle is standing on in python? For example if the the turtle is on a black colored space, he moves forward.

question from:https://stackoverflow.com/questions/65910038/python-turtle-checking-color-under-turtle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Quickly glancing over the turtle documentation, nope, there's no way to detect colors.

You should probably keep a record of which spaces you have drawn so far, adding to the collection whenever you draw a new space. Then, when you want to know the color of an old space, you only need to search through the collection.

What collection you ought to use depends on what kind of spaces we're talking about here. If the spaces are nice tessellated squares, like a chessboard, you could probably get away with a dictionary whose keys are (row,col) coordinate tuples.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...