Justas Tamošiūnas
Justas Tamošiūnas

Reputation: 23

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.

Upvotes: 0

Views: 2773

Answers (1)

Kevin
Kevin

Reputation: 76254

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.

Upvotes: 1

Related Questions