2

How to get Mathematica to trigger an event when a variable inside a Dynamic[] changes?

I want Mathematica to Beep[] when the colour of a pixel on the screen changes. I recommend wiggling some multicolour window in the middle of the screen to test this program. On Mac you can find the coordinates of pixels at the cursor with Command+Shift+4.

<< GUIKit`;
num := Evaluate[numb[thePixel]];
thePixel := GUIScreenShot[{{1280, 1281}, {730, 731}}];
numb = Flatten[ImageData[#, "Byte"]] &;

Dynamic[ Refresh[ Clear[z]; z := num // Total; Evaluate[z],

    UpdateInterval -&gt; .1
 ]

]

Now you should see a number changing as you change the colours of the pixel.


Now how do I get Mathematica to trigger a Beep[] when the number changes?

clues welcome :)

I tried both of the solutions in Detecting changes of variables' values

Conor
  • 7,449
  • 1
  • 22
  • 46

1 Answers1

1

Maybe this way

Dynamic[Refresh[trigger = Total[numb[thePixel]], UpdateInterval -> 0.1, TrackedSymbols :> {}]]
Dynamic[Refresh[trigger; Beep[]; event, TrackedSymbols :> {trigger}]]
Coolwater
  • 20,257
  • 3
  • 35
  • 64