Heart beat monitor
The purpose is to show the aftercare of heart beat like in an hospital.
This example use des sprites and scripts.
I suppose you know well how to create objects, thus I will not insist on.
⇒ animation ⇐
Remarks :
- When a set of pulses is emitted, the first echoe has got for theoritical form sint / t which takes the value 1 when t -> 0. We gonna reproduce it.
We'll use a tracer to simulate scanning.
- In a script with onEnterFrame(), we can't use
PlaySound method, unlike to onFrame().
So I'll use the following trick : inserting an empty sprite with an embedded sound.
Creating Objects
1 - Set up Movie sizes 400x400 ( background color #000033). Frame Rate200.
2 - Now create a circle green colored : X = 0 Y = 0 W = 2 H = 2
Anchor point : Center
3 - Convert into sprite ( name : dot , Target toggled )
Menu Modify / Convert / Convert to sprite.
4 - Then create an horizontal line green colored : X = 0 Y = 200 W=160

Convert into sprite.
5 - Create another horizontal line green colored : X = 240 Y = 400 W=160 ( line : 2 )
Convert into sprite. (nom : right Target : coché )
6 - Now create a vertical line red colored (Anchor point : Bottom center )
X = 200 Y= 200 H = 100

Convert into sprite.
7 - Then create a circle red colored X = 0 Y = 200 W = 2 Y = 2
Set a radial color gradient. (W+R+W)

Convert into sprite.
8 - Create an empty sprite : menu Insert / Sprite.
Name it son Target toggled.
Scripts
In Outline, select Scene_1. Enter the following script :
onLoad()
{
// decrease horizontal line alpha
right._alpha = 50;
left._alpha = 50;
// height width scene
H = int(_root._height);
W = int(_root._width);
a = 100; // scale
n = 800; // number of points
}
function f ( xxx )
{
if ( xxx == 0 ) return 1; // ( sin t / t) → 1 when t → 0
return ( Math.sin(xxx) / xxx );
}
onFrame (1,afterPlacedObjectEvents)
{
// set a range
xn = -40; xp = 40;
increment = (xp-xn) / n;
// display ( sin t / t )
for (i=1; i < n; i++)
{
duplicateSprite(dot, "dot"+i, i);
("dot"+i)._alpha = 40; // decrease alpha
("dot"+i)._X = (W / 2) + xn + i*increment;
yr = a*f(xn + i*increment);
("dot"+i)._Y = (H / 2) - yr;
}
dot._alpha = 0; // 0 for the basic sprite
}
In Outline, select sprite son. Enter the following script :
onFrame(1) { stop(); } // don't play at startup
onFrame (2) { playSound("beat.wav"); }
In Outline, select sprite spot. Enter the following script :
onLoad()
{
_X = 0; // initial position
_alpha = 100;
}
onEnterFrame(includingFirstFrame)
{
_X += 2; // increase X 2 pixels
// if in X-range (sint /t) , we hide
if ( (_X >= 160) && (_X < 240) )
_alpha = 0;
else _alpha = 100; // either display
// off right limit? go back initial pos.
if ( _X >= _root.W) _X = 0;
}
In Outline, select sprite beep. Enter the following script :
onLoad()
{
_X = 0; // initial position
_yscale = 2; // % Y-scale
delta = 0; // init
}
onEnterFrame(includingFirstFrame)
{
_X += 2; // increase 2 pixels
debut = 160; // end of H-line left
fin = debut + 80; // beginning of line right
/* In the range of (sin t / t) we build a vertical
line whose end follows the curve, which simulates scanning */
if ( (_X >= debut) && (_X < fin) )
{
start = -40;
_yscale = _root.a * _root.f( start + delta) ;
if ( (start + delta) == 0) _root.son.gotoAndPlay(2);
delta += 2; // folllow _X
}
else // beyond right limit? go back
if ( _X >= _root.W)
{
_yscale = 2;
_X = 0;
delta = 0;
}
}
Et voilà, that's it.


