Jeff Ostergaard
Programming Concepts and Applications

ACCAD 756


Task# 09
Selection
Due Date November 5, 2002
Source Code

//
// Ostergaard, Task 09
// Selection
//
//
// circles used
var circles = new Array(circle01, circle02, circle03);
// create new paths (speed & direction)
var xDir = new Array(1.25,1.3,3);
var yDir = new Array(1.05,1.4,1.2);
// controls speed
var maxSpeed = 10;
// 3 velocity variables w/ random rate change
var speed = new Array(newSpeed(maxSpeed), newSpeed(maxSpeed), newSpeed(maxSpeed));
var radius = circle._width * .5;
var t = 0;
//
//
//
function updateFrame() {
    // scale circles
    for (i=0; i<3; i++) {
         circles[i]._xScale = 200;
         circles[i]._yScale = 200;
    }
   // loop checks the x and y values of the circles
   // if a circle is on the edge of the canvas it returns an inverse value
   for (i=0; i<3; i++) {
         // prevents circles from edge cropping
         t = (t + .01) % (Math.PI * 2);
         circles[i]._x += speed[i] * xDir[i];
         circles[i]._y += speed[i] * yDir[i];
      if (circles[i]._x < radius) {
         circles[i]._x = radius;
         xDir[i] *= -1;
         speed[i] = newSpeed(maxSpeed);
       }
      else if (circles[i]._x > Stage.width - radius) {
         circles[i]._x = Stage.width - radius;
         xDir[i] *= -1;
         speed[i] = newSpeed(maxSpeed);
       }
      if (circles[i]._y < radius) {
         circles[i]._y = radius;
         yDir[i] *= -1;
         speed[i] = newSpeed(maxSpeed);
       }
      else if (circles[i]._y > Stage.height - radius) {
         circles[i]._y = Stage.height - radius;
         yDir[i] *= -1;
         speed[i] = newSpeed(maxSpeed);
       }
   }
}
// change in velocity of the circles after an inverse value has been returned
function newSpeed(tops) {
    var base = tops * .4;
    var extra = tops * .6;
    return (Math.random() * extra + base);

}
// associate a function with the enterFrame event
this.onEnterFrame = updateFrame;