<HTML> 
<HEAD>
<TITLE>DirectAnimation SDK, JScript sample</TITLE>
<SCRIPT LANGUAGE="JScript">
<!--
if (window.top.frames.length!=0 && window.top.frames[0].ShowNoButtons!=null)
    window.top.frames[0].ShowNoButtons();
//-->
</SCRIPT>
</HEAD>	 

<BODY BGCOLOR=WHITE TOPMARGIN=15 LEFTMARGIN=20>
<FONT FACE="Verm.na, Arial, Helvetica" SIZE=2> 
<CENTER>
<H1>Periodic Randomness using the core scripting interface</H1>
</CENTER>

<OBJECT ID="DAControl"
   STYLE="position:absolute; left:30%; top:100;width:300;height:300" 
   CLASSID="CLSID:B6FFC24C-7E13-11D0-9B47-00C04FC2F51D">
</OBJECT>

<SCRIPT LANGUAGE="JScript">
<!--
  m = DAControl.MeterLibrary;

  // This is my animation... just a bunch of colored blocks whose color and
  //  position are randomly changing by using the function below
  img = m.EmptyImage;
  for(i=0; i<10; i++) {
    block = m.SolidColorImage(m.ColorRgbAnim(periodicRandom(3),
                                             periodicRandom(3),
                                             periodicRandom(3)));
    block = block.Crop(m.Point2(-.002,-.002),m.Point2(.002,.002));

    xf = m.Compose2(     
            m.Translate2Anim( m.Mul(periodicRandom(3*Math.random()),m.DANumber(.06)),
                              m.Mul(periodicRandom(3*Math.random()),m.DANumber(.06)) ),
            m.Translate2( -.035, -.035 ) );
    block = block.Transform(xf);
    img = m.Overlay(img, block);
  }

  DAControl.Image = img
  DAControl.BackgroundImage = m.SolidColorImage(m.White);
  DAControl.Start();

  // This function generates a DANumber that randomly changes after 
  // the interval length has expired...
  function periodicRandom(interval) {
    random = m.SeededRandom(Math.random()).RunOnce(); 
    ev = m.Always.Snapshot(random);
    randomInterval = new ActiveXObject("DirectAnimation.DANumber");
    randomInterval.Init(
      m.Until( m.UntilEx( m.DANumber(Math.random()), ev ), 
      m.Timer(interval), randomInterval));
    return randomInterval;
  }
-->
</SCRIPT>
</FONT>
</BODY>
</HTML>
