# Making graphic objects disappear interactively

I am trying to create a program where dots on a plane disappear when an object passes over them. I am using EventHandler to code the arrow keys for control of the object. I want each dot to individually disappear when the object passes over them, and for the score of the game to increase by 10 points for every dot. I am pretty sure I will be able to code the score to increase once I figure out how to make the dots disappear. Here is my code for the dots using an image to decide the placement of the dots:

bin = Opening[ColorNegate @ Binarize[p], 20];
thin = Thinning[SelectComponents[bin, "Count", -1], Method -> "MedialAxis"];
g = MorphologicalGraph[thin, VertexSize -> 100, VertexStyle -> Pink];
vertices = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates];
vrules = Sort[Rule @@@ Transpose[{VertexList[g], vertices}]];
good = Select[

dots = Union @
Flatten[Module[{a = #1 /. vrules, b = #2 /. vrules, d},
d = .2 + .2/10 Round[EuclideanDistance[a, b], 30];
a + #/d (b - a) & /@ Range[0, d]] & @@@ good, 1];

Show[p, Graphics[{PointSize[Large], Pink, Point /@ dots}],


I am thinking an If function could work where a single dot changes color to black (the color of the background) when the controlled object is in the same position as the dot. Or if there is a way to make the dot become invisible that would work as well. And tips or ideas will be helpful!

This is the code I have tried but is not working:

If[Point /@ dots == object, DeleteCases[dots], Nothing];


It does not even give me an error message; nothing changes when evaluating my code with this command.

EDIT: The image p I am using is

• Your code is incomplete and does not run. What is vrules? What is p? – bill s Dec 11 '16 at 2:18
• p is the image I am using, I edited the question to include the code leading up to my dots function – Savannah S Dec 11 '16 at 2:22
• But we can't run this without p since it is used throughout. Please upload the picture. – bill s Dec 11 '16 at 2:34
• The code doesn't work with randomly selected images. – Feyre Dec 12 '16 at 10:41
• I have edited the code within the question to include the image I am using – Savannah S Dec 12 '16 at 23:47