MathGroup Archive 2009

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

Search the Archive

Change Figure according to Session Time

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98990] Change Figure according to Session Time
  • From: Sunt <SunTing.05 at gmail.com>
  • Date: Thu, 23 Apr 2009 06:44:17 -0400 (EDT)

Hi community,

First,some definitions following:

(*define a dancer figure*)
dancer[n_Integer: 1, v_Integer, figure_List] :=
  Graphics@{Line[{figure[[v, 1]] - {0, 0.25} + {2 n, 0},
      figure[[v, 7]] + {2 n, 0}, figure[[v, 2]] + {2 n, 0}}],(*torso*)
    Line[{figure[[v, 2]] + {2 n, 0}, figure[[v, 3]] + {2 n, 0},
      figure[[v, 4]] + {2 n, 0}}],(*right leg*)
    Line[{figure[[v, 2]] + {2 n, 0}, figure[[v, 5]] + {2 n, 0},
      figure[[v, 6]] + {2 n, 0}}],(*left leg*)
    Line[{figure[[v, 7]] + {2 n, 0}, figure[[v, 8]] + {2 n, 0},
      figure[[v, 9]] + {2 n, 0}}],(*right arm*)
    Line[{figure[[v, 7]] + {2 n, 0}, figure[[v, 10]] + {2 n, 0},
      figure[[v, 11]] + {2 n, 0}}],(*left arm*)White,
    Disk[figure[[v, 1]] + {2 n, 0}, 0.25],(*head-- eclipses neck/
    shoulders if necessary*)Black,
    Circle[figure[[v, 1]] + {2 n, 0}, 0.25] (*head*)};
locators = {(*1*){(*head*){0, 0.75},(*groin*){0,
     0},(*right knee*){-0.3, -0.4}, {-0.2, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, -0.9},(*collar*){0, 0.4},(*elbows*){-0.4, 0.3}, {-0.8,
     0.5},(*hands*){0.6, 0.4}, {0, 0}},(*=D7=F3=CA=D6=B2=E6=D1=FC*)(*2*){(*=
head*){-0.07,
     0.75},(*groin*){0.,
     0.},(*right knee*){-0.4, -0.07}, {-0.07, -0.5},(*left \
knee*){0.1, -0.4}, {0.1, -0.9},(*collar*){0, 0.3},(*right arm*){-0.4,
     0.25}, {-0.9, 0.3},(*left arm*){0.3, 0.7}, {0.3,
     1.2}},(*=BD=F0=BC=A6=B6=C0=C1=A2*)(*3*){(*head*){0, 0.75},(*groin*){0.=
,
     0.},(*right knee*){-0.3, -0.3}, {-0.7, -0.6},(*left knee*){0.4, \
-0.3}, {0.8, -0.6},(*collar*){0, 0.3},(*right arm*){-0.7,
     1.1}, {-0.85, 1.15},(*left arm*){0.6, 0.7}, {0.2,
     1.1}},(*=CB=C4=D6=AB=D5=B9=BF=AA*)(*4*){(*head*){0, 0.75},(*groin*){0.=
,
     0.},(*right knee*){-0.4, -0.2}, {-0.3, -0.6},(*left knee*){0.4, \
-0.2}, {0.3, -0.6},(*collar*){0, 0.3},(*right arm*){-0.5, 0.4}, {-0.4,
      0.8},(*left arm*){0.5, 0.4}, {0.4,
     0.8}},(*=C2=DE=C8=A6=CD=C8=BE=D9=CA=D6*)(*5*){(*head*){0, 0.75},(*groi=
n*){0,
     0},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.3, \
-0.4}, {0.2, -0.9},(*collar*){0, 0.4},(*elbows*){-0.6, 0.4}, {0,
     0},(*hands*){0.4, 0.3}, {0.8, 0.5}},(*=D3=D2=CA=D6=B2=E6=D1=FC*)(*6*){=
(*head*){0,
     0.75},(*groin*){0.,
     0.},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, -0.9},(*collar*){0,
     0.35},(*right arm*){-0.5, -0.1}, {-0.7,
     0.1},(*left arm*){0.5, -0.1}, {0.7,
     0.1}},(*=CB=AB=CA=D6=B5=CD=B7=C5*)(*7*){(*head*){0.07, 0.75},(*groin*)=
{0.,
     0.},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, -0.9},(*collar*){0, 0.3},(*right arm*){-0.25,
     0.6}, {-0.2, 1.2},(*left arm*){0.15,
     0.15}, {0.3, -0.3}},(*=BE=D9=C6=F0=D2=BB=D6=BB=CA=D6*)(*8*){(*head*){-=
0.07,
     0.75},(*groin*){0.,
     0.},(*right knee*){-0.3, -0.5}, {-0.4, -0.4},(*left knee*){0.1, \
-0.4}, {-0.2, -0.8},(*collar*){0, 0.3},(*right arm*){-0.5,
     0.1}, {-0.6, 0.2},(*left arm*){0.1, 1.1}, {-0.03,
     1.15}},(*=CE=D2=D2=AA=B7=C9*)(*9*){(*head*){-0.07, 0.75},(*groin*){0.,
     0.},(*right knee*){-0.6, 0.6}, {-0.8,
     0.76},(*left knee*){0.1, -0.4}, {0.2, -0.8},(*collar*){0,
     0.3},(*right arm*){-0.3, 0.5}, {-0.45, 1.0},(*left arm*){0.3,
     0.5}, {0.45, 1.0}},(*=CC=A7=C6=F0=D2=BB=CC=F5=CD=C8*)(*10*){(*head*){0=
.2,
     0.75},(*groin*){0.,
     0.},(*right knee*){0.1, -0.4}, {0.2, -0.8},(*left knee*){0.4, \
-0.3}, {0.8, -0.6},(*collar*){0.13, 0.325},(*right arm*){-0.3,
     1.1}, {-0.4, 1.0},(*left arm*){0.5, 0.1}, {0.8,
     0.05}},(*=B7=C9=CF=E8*)(*11*){(*head*){0.07, 0.75},(*groin*){0.,
     0.},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, -0.9},(*collar*){0, 0.3},(*right arm*){-0.45,
     0.45}, {-0.1, 0.65},(*left arm*){0.5, 0.15}, {0,
     0.05}},(*=BD=BB=B2=E6=CA=D6*)(*12*){(*head*){0.145, 0.55},(*groin*){0.=
,
     0.},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, -0.9},(*collar*){0, 0.3},(*right arm*){-0.5, 0.4}, {-0.4,
      0.8},(*left arm*){0.5, 0.4}, {0.4,
     0.8}},(*=D6=BB=BE=D9=CA=D6*)(*13*){(*head*){0.125, 0.75},(*groin*){0.,
     0.},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, 0.3},(*collar*){0, 0.3},(*right arm*){-0.5, 0.4}, {-0.4,
     0.8},(*left arm*){0.5, 0.4}, {0.4,
     0.8}},(*=CC=A7=D3=D2=CD=C8=BE=D9=CA=D6*)(*14*){(*head*){0.135, 0.65},(=
*groin*){0.,
     0.},(*right knee*){-0.2, -0.4}, {-0.3,
     0.3},(*left knee*){0.2, -0.4}, {0.3, -0.9},(*collar*){0,
     0.3},(*right arm*){-0.5, 0.4}, {-0.4, 0.8},(*left arm*){0.5,
     0.4}, {0.4, 0.8}},(*=CC=A7=D7=F3=CD=C8=BE=D9=CA=D6*)(*15*){(*head*){0,=
 0.75},(*groin*){0.,
      0.},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2,
\
-0.4}, {0.3, -0.9},(*collar*){0, 0.3},(*right arm*){-0.5, 0.6}, {0,
     1.2},(*left arm*){0.5, 0.6}, {0,
     1.2}},(*=CB=AB=CA=D6=BD=BB=B2=E6=D7=B4*)(*16*){(*head*){-0.125, 0.75},=
(*groin*){0.,
     0.},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, 0.3},(*collar*){0, 0.3},(*right arm*){-0.5, 0.6}, {0,
     1.2},(*left arm*){0.5, 0.6}, {0,
     1.2}},(*=CB=AB=CA=D6=BD=BB=B2=E6=CC=A7=D3=D2=CD=C8*)(*17*){(*head*){-0=
.125, 0.75},(*groin*){0.,
     0.},(*right knee*){-0.2, -0.4}, {-0.3,
     0.3},(*left knee*){0.2, -0.4}, {0.3, -0.9},(*collar*){0,
     0.3},(*right arm*){-0.5, 0.6}, {0, 1.2},(*left arm*){0.5,
     0.6}, {0, 1.2}},(*=CB=AB=CA=D6=BD=BB=B2=E6=CC=A7=D7=F3=CD=C8*)(*18*){(=
*head*){-0.125,
     0.75},(*groin*){0.,
     0.},(*right knee*){-0.2, -0.4}, {0, -0.9},(*left knee*){0.2, \
-0.4}, {0, -0.9},(*collar*){0, 0.3},(*right arm*){-0.5, 0.6}, {0,
     1.2},(*left arm*){0.5, 0.6}, {0,
     1.2}},(*=D0=A1=CC=EC=B6=EC=CE=E8=B2=BD*)(*19*){(*head*){0.125, 0.75},(=
*groin*){0,
     0},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, -0.9},(*collar*){0, 0.4},(*elbows*){-0.6, 0.4}, {-0.6,
     1.0},(*hands*){0.4, 0.3}, {0.8,
     0.5}},(*=B7=C5=CF=C2=D3=D2=CA=D6*)(*20*){(*head*){-0.125, 0.75},(*groi=
n*){0,
     0},(*right knee*){-0.2, -0.4}, {-0.3, -0.9},(*left knee*){0.2, \
-0.4}, {0.3, -0.9},(*collar*){0, 0.4},(*elbows*){-0.4, 0.3}, {-0.8,
     0.5},(*hands*){0.6, 0.5}, {0.6, 1.0}}(*=B7=C5=CF=C2=D7=F3=CA=D6*)};


(*sn1 for SoundNote pitch, sn2 for duration of according note*)
sn1 = {-9, -9, -5, -5, -9, -9, -9, 3, -7, -7, -7, -4, -4,
   0, -4, -7, -2, 5, 10, 10, 2, 2, 5, 2, -9, -9, -5, -5, -5,
   3, -9, -2};
sn2 = {.00001, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3,
   3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, .00001};
sn2c = Accumulate@sn2/8;
sn2s = Table[{sn2c[[i]], sn2c[[i + 1]]}, {i, Length[sn2c] - 1}];

(*pos changing according to Session Time, in order to get
corresponding note in sn1*)
pos := Position[sn2s, {_, _}?((#[[1]] < t <= #[[2]]) &)][[1, 1]];
pos1 = pos;
pos2 = pos;

(*offset as the name means, t for time starts form offset*)
offset = SessionTime[];
t := SessionTime[] - offset;

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!



  • Prev by Date: Re: Re: Re: Mathematica for gifted elementary
  • Next by Date: Plot x to y and y to x
  • Previous by thread: Re: Bug in Rational arithmetic?
  • Next by thread: Re: Change Figure according to Session Time