1
$\begingroup$

I fail to see why the following code does not turn the hand at the same rate as the minute hand of a clock:

DynamicModule[{incr, s},
    incr = Pi / (2.0 * 15 * 60);
    s = (Pi / 2.0) + incr;
    Graphics[{
        Circle[],
        Dynamic[
            Refresh[s -= incr; Line[{{0, 0}, {Cos@s, Sin@s}}], UpdateInterval -> 1]
            (*, TrackedSymbols :> {} stops the movement entirely *)
        ]
    }]
]

It seems that UpdateInterval has no effect. Not matter the value to which it is set, the hand moves at the same speed. And, as indicated in the comment inside the code, setting the TrackedSymbols option stops the movement of the hand entirely.

EDIT

It turns out that I simply had to quit the notebook and restart that. That solved the problem for me.

$\endgroup$
1
$\begingroup$

This works for me:

DynamicModule[{incr, s},
    incr=Pi/(2.0*15*60);
    s=(Pi/2.0)+incr;
    {
        Graphics[
            {
            Circle[],
            Dynamic[
                s-=incr; Line[{{0,0},{Cos@s,Sin@s}}],
                TrackedSymbols->{},
                UpdateInterval->1
            ]
            }
        ],
        Dynamic[s]
    }
]
| improve this answer | |
$\endgroup$
  • $\begingroup$ I have copy-pasted your code, and it does not work for me. The TrackedSymbols line stops any movement. Its removal brings back the same behaviour as before (i.e. as the original code). (Windows 10 Professional 64-bit, Mathematica 11.3, all the latest updates applied.) $\endgroup$ – Shredderroy Oct 15 '18 at 16:16
  • $\begingroup$ @Shredderroy What Mathematica version? $\endgroup$ – Carl Woll Oct 15 '18 at 16:17
  • $\begingroup$ Version 11.3. I was a little late to anticipate that question, but I have added the information to my previous comment as an edit. $\endgroup$ – Shredderroy Oct 15 '18 at 16:18
  • $\begingroup$ Does DynamicModule[{x}, Dynamic[x++, TrackedSymbols -> {}, UpdateInterval -> 1], Initialization :> (x = 0)] work for you? $\endgroup$ – Carl Woll Oct 15 '18 at 16:21
  • 1
    $\begingroup$ Alright! That was it. I had to quit the notebook and restart it. Thank you! I will accept your answer. $\endgroup$ – Shredderroy Oct 15 '18 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.