In working on a simple simulation I came across the following Manipulate quirk (bug?) and I want to know how to get around it. Here is the first pass code, which acts as expected (but is incorrect):
simpleBrownianSimulation[] := Module[{vels, nPts},
Manipulate[
vels = Table[RandomReal[{-1, 1}, 2], {Length[pts]}];
nPts = Table[pts[[i]] + t*vels[[i]], {i, Length[pts]}];
Graphics[{Blue, PointSize[0.02], Point[nPts]},
PlotRange -> {{-5, 5}, {-5, 5}}],
{{pts, {{0, 0}}}, Locator, LocatorAutoCreate -> True, Appearance -> None},
{t, 0, 10, 0.05}
]];
simpleBrownianSimulation[]
The idea is to use the slider to trigger updates to the particles (stored in pts) position. This code correctly updates only if the slider is moved, but contains an error, since the position is computed always from the initial position of the particle, and the current time value. So to fix this, I changed it to:
simpleBrownianSimulation[] := Module[{vels, nPts, isSet = False},
Manipulate[
If[!isSet, nPts = pts; isSet = True];
vels = Table[RandomReal[{-1, 1}, 2], {Length[pts]}];
nPts = Table[nPts[[i]] + vels[[i]], {i, Length[pts]}];
Graphics[{Blue, PointSize[0.02], Point[nPts]}, PlotRange -> {{-5, 5}, {-5, 5}}],
{{pts, {{0, 0}}}, Locator, LocatorAutoCreate -> True, Appearance -> None},
{t, 0, 10, 0.05}
]];
simpleBrownianSimulation[]
This code is correct, but it ANIMATES! It updates on its own regardless of whether the slider is being moved or not. I know that here the value of the slider is not used, that is fine. I just want to use it as an update trigger, and NOT have maniuplate update otherwise. Why is manipulate doing this and how can I fix it? Note that this is Mathematica 9, but this occurs both on the Windows and Mac versions.