MathGroup Archive 2009

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

Search the Archive

Re: Change Figure according to Session Time

  • To: mathgroup at
  • Subject: [mg99033] Re: [mg98990] Change Figure according to Session Time
  • From: John Fultz <jfultz at>
  • Date: Fri, 24 Apr 2009 03:49:11 -0400 (EDT)
  • Reply-to: jfultz at

On Thu, 23 Apr 2009 06:44:17 -0400 (EDT), Sunt wrote:
> Hi community,
> First,some definitions following:
> I'm really puzzled by the following codes:
> Dynamic[
> Clock[1];
> Panel[
> If[pos2 != pos1 && t < 8.1,
> pos2 = pos;
> pd = dancer[1, RandomInteger[{1, 20}], locators];
> EmitSound[
> Sound[
> SoundNote[
> sn1[[pos]],sn2[[pos]]
> ]
> ]
> ]
> ]
> ]
> pos1 = pos;
> ]
> I meant to emit sound and display a dancer figure corresponding to
> every change of sound while time passing, but I can't realize it.
> How to do it?
> Thanks a lot!

You can't expect a Dynamic expression of the form...

=09<some calculations>;
=09<some more calculations>

to produce a graphic.  The graphic is hidden by being in the middle of a 
compound expression.  This wouldn't show a graphic if you evaluated it
without the Dynamic, so you certainly can't expect it to show a graphic
inside a Dynamic.  To better understand Dynamic, you should read
the beginning and advanced Dynamic tutorials (linked to from the
Dynamic documentation), as well as this post of mine from February...

I snipped the .00001 values out of your sn2 and used the following code which 
illustrates a few different principles.  All of this is well documented in the 
appropriate function documentation, so I won't go into much detail here.

DynamicModule[{time, counter = 1, random = 1},
     time < 0.01,
     counter = 0,
     counter == 0,
     counter == Length[sn2c],
     Null (* do nothing *),
     time > sn2c[[counter]],
     random = RandomInteger[{1, 20}]; 
     EmitSound[Sound[SoundNote[sn1[[counter]], sn2[[counter]]]]]
    dancer[1, random, locators]]
   Trigger[Dynamic[time], {0, Last[sn2c]}, 1], Top]]]

I also added an explicit ImageSize to the graphic to keep it from hopping 

Since the code was a little munged by the process of emailing it, and it was
also a little long, I just put a notebook with the working demo here...

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

  • Prev by Date: Re: fitting surface with Mathematica 6.0.3 and range of fitted values
  • Next by Date: Re: Re: Help with Speeding up a For loop
  • Previous by thread: Change Figure according to Session Time
  • Next by thread: Re: Change Figure according to Session Time