I have a moving clock
Dynamic[Refresh[ClockGauge[], UpdateInterval -> 1]]
which should be clickable.
Program should make a sound when hand of a clock will touch the point where I clicked before.
I found something like this:
EventHandler[
Framed@"Play", {"MouseClicked" :>
EmitSound[Sound@SoundNote["C", 10*^10, "Flute"]],
"MouseExited" :> EmitSound[Sound@SoundNote[SoundVolume -> 0]]}]
to make a sound on click.
But I don't know how to get the position of clicked point.
Answer
Here is a quick first draft:
DynamicModule[{s = 0, pt = {0, 1}},
Column@{ClickPane[
Dynamic[Show[Refresh[Graphics[ClockGauge[]], UpdateInterval -> 1],
Graphics[{Red, Point[pt]}]]],
(pt = #; s = 30*(1 + ArcTan[-pt[[2]], -pt[[1]]]/Pi)) &],
DynamicWrapper[Dynamic@s,
If[DateValue["Second"] == Round[s],
EmitSound[Sound@SoundNote["C", 0.5, "Flute"]]],
UpdateInterval -> 1]}]
I'll leave the further refinement to you.
In response to a comment.
Using the value of Clock
:
DynamicModule[{pt = {0, 1}, secondHand = Line[{{0, 0}, {0, 55}}], clock = 0},
Column@{ClickPane[
Dynamic[Show[Graphics[Circle[{0, 0}, 60]],
Graphics[
Dynamic[{Rotate[secondHand, (clock = Clock[{0, 59, 1}])*-Pi/30, {0, 0}]}]],
Graphics[{Red, Point[pt]}]]],
(pt = #; s = 30*(1 + ArcTan[-pt[[2]], -pt[[1]]]/Pi)) &],
DynamicWrapper[Dynamic@s,
If[clock == Round[s],
EmitSound[Sound@SoundNote["C", 0.5, "Flute"]]],
UpdateInterval -> 1]}]
Using the rotated secondHand
:
DynamicModule[{pt = {0, 1}, secondHand = Line[{{0, 0}, {0, 55}}], rSH},
Column@
{ClickPane[
Dynamic[Show[Graphics[Circle[{0, 0}, 60]],
Graphics[
Dynamic[{rSH = Rotate[secondHand, Clock[{0, 59, 1}]*-Pi/30, {0, 0}]}]],
Graphics[{Red, Point[pt]}]]],
(pt = #; s = 30*(1 + ArcTan[-pt[[2]], -pt[[1]]]/Pi)) &],
DynamicWrapper[Dynamic@s,
If[rSH[[2]]*-30/Pi == Round[s],
EmitSound[Sound@SoundNote["C", 0.5, "Flute"]]],
UpdateInterval -> 1]}]
Comments
Post a Comment