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*)};
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*){(*=
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,
,
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,
,
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,
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*){=
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.,
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.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,
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,
.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.},(*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.},(*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.},(*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,
*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.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,
(*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,
.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*){(=
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,
*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,
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