MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: pause button for Dynamic?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113741] Re: pause button for Dynamic?
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Wed, 10 Nov 2010 06:27:51 -0500 (EST)

On Tue, 9 Nov 2010 03:55:32 -0500 (EST), Gianluca Gorni wrote:
>
> Hello,
>
> I have a simple simulation of a Brownian motion
>
> DynamicModule[{brown == {0, 0}},
> Framed@Graphics[
> Dynamic[Point[
> brown +== RandomReal[NormalDistribution[0, 1/300], 2]]],
> PlotRange -> 1]]
>
> How can I add a pause/play button?
>
> At the moment the only way I know to stop the animation
> is to delete the output cell.
>
> Thank you in advance,
> Gianluca Gorni

There are several ways to do this.  Here's a couple to give you some ideas.
First, a method that uses a Dynamic[] value of the DynamicUpdating option:

DynamicModule[{brown == {0, 0}, update == True},
 Column[{Row[{Checkbox[Dynamic[update]], " Run animation"}],
   Style[Framed@
     Graphics[
      Dynamic[Point[
        brown +== RandomReal[NormalDistribution[0, 1/300], 2]]],
      PlotRange -> 1],
    DynamicUpdating -> Dynamic[update]]}]]

Another is to use TrackedSymbols to track an Animator[]:

DynamicModule[{brown == {0, 0}, anim},
 Column[{Animator[Dynamic[anim]],
   Framed@Graphics[
     Dynamic[Point[anim;
       brown +== RandomReal[NormalDistribution[0, 1/300], 2]],
      TrackedSymbols :> {anim}], PlotRange -> 1]}]]
]

In both cases, the addition of controls causes the graphic to shrink
automatically to a smaller size, so you may wish to add ImageSize->Medium as an
option to the Graphics[] expression.

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


  • Prev by Date: Re: Writing functions in packages that define values of global variables
  • Next by Date: Re: DownValues
  • Previous by thread: Re: pause button for Dynamic?
  • Next by thread: Writing functions in packages that define values of global variables