4
$\begingroup$

This question came about because of my failure to implement an answer to this previous question. My idea was that an answer could be written using aClickPane and anAnimator.

Code

points[goal : {_, _}, nPts_Integer] :=
  Table[i goal, {i, 0, 1, 1/(nPts - 1)}]

With[{wayPts = 5},
  DynamicModule[{pts = points[{40, 40}, wayPts], k, t},
   k = t = Length @ pts;
   Column[{
     Animator[
       Dynamic @ k, {1, Dynamic @ Length@pts, 1}, 1,
       AppearanceElements -> "ResetPlayButton",
       AnimationRepetitions -> 1,
       AnimationRunning -> False,
       AnimationRunTime -> Dynamic @ t],
     Dynamic @
       ClickPane[
         Graphics[{Red, Disk[pts[[k]], 3]},
           PlotRange -> {{-50, 50}, {-50, 50}},
           ImageSize -> Medium,
           Frame -> True],
         (Which[
            k >= Length @ pts && t >= 0., t = 0.; k = 1; pts = points[#, wayPts],
            k == 1 && t == 0., pts = points[#, wayPts]]&)],
       (* debugging info *)
       Dynamic @ t, Dynamic @ k}]]]

moving-dot

Instructions for use

  1. Click in the pane to establish a target point; the dot will move to the origin.

  2. Click on the ResetPlay button (top-left); the dot will move along a straight line to the target point in discrete steps.

The problem

The code misbehaves. It does everything that it is supposed to do, but it also does something that is totally unexpected and unwanted – after moving the dot to the target point, it immediately returns the dot to the origin and moves it back to the target point. This second iteration of the moves is strange in that only indexes 1, 2, and 5 appear, 3 and 4 are skipped.

I have not been able to determine why the animator makes a second iteration or how to fix it. I have little experience with animators. This is first time I have tried to control one dynamically.

Questions

  1. Is this misbehavior version and/or platform dependent? I'm running V10.0.2 on OS X 10.6.8 (Snow Leopard).

  2. Is there a better strategy for controlling the animator, so that it runs only one iteration of the index values and then stops?

Update

Inspired by beliarius' comment, I investigated this problem in V9. I found that the option AnimationRunTime -> Dynamic @ t is not support there. I removed it and all references to variable t. The code then ran with no sign of any misbehavior. I then tried the modified code in V.10.0.2 and the misbehavior still occurred. This make me think I have run into a bug in V.10.0.2,

Here is the modified code for anyone who wants to experiment with it.]

With[{wayPts = 5},
  DynamicModule[{pts = points[{40, 40}, wayPts], k},
   k = Length @ pts;
   Column[{
     Animator[
       Dynamic @ k, {1, Dynamic @ Length @ pts, 1}, 1,
       AppearanceElements -> "ResetPlayButton",
       AnimationRepetitions -> 1,
       AnimationRunning -> False],
     Dynamic @
       ClickPane[
         Graphics[{Red, Disk[pts[[k]], 3]},
           PlotRange -> {{-50, 50}, {-50, 50}},
           ImageSize -> Medium,
           Frame -> True],
         (If[k >= Length @ pts, k = 1; pts = points[#, wayPts]] &)],
       (* debugging info *)
       Dynamic @ k}]]]
$\endgroup$
2
  • 2
    $\begingroup$ Mma v9 here. Your code seems to behave as expected. No bugs. $\endgroup$ Feb 14, 2015 at 18:37
  • 1
    $\begingroup$ I can reproduce it on Win7 V10.0.2 $\endgroup$
    – Kuba
    Feb 15, 2015 at 10:48

1 Answer 1

4
$\begingroup$

I reported the issue discussed in this question to Wolfram technical support. I have received the following reply:

It does appear that Animator is not behaving properly in this case and I have forwarded an incident report to our developers with the information you provided.

On the basis of this reply, I have tagged this question with .

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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