Re: Dynamic, UpdateInterval and global variable
- To: mathgroup at smc.vnet.net
- Subject: [mg95650] Re: Dynamic, UpdateInterval and global variable
- From: dh <dh at metrohm.com>
- Date: Sat, 24 Jan 2009 06:16:49 -0500 (EST)
- References: <gl4a43$ge6$1@smc.vnet.net>
Hallo Antoine,
I guess what is happening is that Mathematica tries every second to make a full
update. But because the value of aDisk is changeing all the time, it
will never finish the first update.
To slow down this, you may delete Refresh and put a "Pause" statement
instead:
Dynamic[pt = pt + RandomReal[{0, 0.2}, 2]; Pause[1]; aDisk[pt]]
hope this helps, Daniel
Antoine wrote:
> Hello everybody,
>
>
> With Mathematica, I would like to have a Disk which "evades" from the origin in a Dynamic,
> with an UpdateInterval of 1 second.
>
>
> To fix the ideas the function
>
>
> aDisk[{x_, y_}] :=
> Graphics[Disk[{x, y}, 0.2], PlotRange -> {{-2, 2}, {-2, 2}},
> Axes -> True, AxesStyle -> RGBColor[0.47451, 0.482353, 0.47451]]
>
>
> will draw in disk of center {x,y}, radius 0.2, in a fixed PlotRange.
> Everything is fine.
>
>
> The following code:
>
>
> ListAnimate[
> Map[aDisk, NestList[# + RandomReal[{0, 0.2}, 2] &, {0., 0.}, 10]]]
>
>
> does what I want in a ListAnimate.
>
>
> I would like the same in a Dynamic instruction. In the following lines
> the problem is the global variable pt. It seems that the option UdpdateInterval
> is not "respected" when a global variable is used:
>
>
> pt = {0, 0};
> Dynamic[Refresh[pt = pt + RandomReal[{0, 0.2}, 2]; aDisk[pt],
> UpdateInterval -> 1]]
>
>
> Mathematica does not "wait" a second. The Disk evades quickly ...
>
>
> What should I write to see the disk going slowly up-right in a Dynamic ?
> I have tried with Module, DynamicModule, but nothing worked out.
>
>
> Thank you very much for your help.
>
>
> Antoine.
>