MathGroup Archive 2009

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

Search the Archive

Re: Change Figure according to Session Time

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

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...

Dynamic[
=09<some calculations>;
=09<graphic>;
=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...

http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00424.html

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},
 Panel[
  Labeled[
   Dynamic[
    Which[
     time < 0.01,
     counter = 0,
     counter == 0,
     counter++,
     counter == Length[sn2c],
     Null (* do nothing *),
     time > sn2c[[counter]],
     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 
around.

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...

http://download.wolfram.com/?key=U8N68F

Sincerely,
 
John Fultz
jfultz at wolfram.com
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