This bit of code runs a little animation of a stochastic process:
(* a random walk bm, its min and max *)
{bm, m, M} = {Table[Random[] - .5, {100}] // Accumulate, Min[bm], Max[bm] }
(* plot of trajectory of bm up to i-th step *)
traj[i_] := ListLinePlot[({Range[1, 100], bm} // Transpose)[[;; i]],
Joined -> True, PlotRange -> {{0, 100}, {m, M}}]
(* animation using Clock *)
q = Dynamic[r = Clock[{1, 100, 1}, 5, 1]; traj[r] ]
Next I'd like to use Button to run the animation. Something like
Button["Run", q]
but this doesn't work.
Eventually I'd like to have two buttons, "Repeat" and "Clear" like this:
x = {{0, 0}};
min[x_] := (Sort[x, #1[[2]] < #2[[2]] &])[[2]]; Column[ {Row[{Button["Repeat",
x = Append[x, { Random[], Random[] }]],
Button["Reset", x = { {0, 0}}] } ],
Dynamic[Show[{ ListPlot[x, PlotRange -> {{0, 1}, {0, 1}}, ImageSize -> 300,
Frame -> True, Axes -> None] , If[Length[x] > 1,
Graphics[{Red, Line[{min[x], {min[x][[1]], -.1} }]}], {}],
If[Length[x] > 1,
Graphics[{Red, Line[{min[x], {0, min[x][[2]]} } ]}], {}]
}]]}]
but instead of dots, I want to plot animated functions involving Clock.
