Task 08
********************************
// define a function to perform updates to the stage
function circleAnimationstep(whichCircle, bounds) {
// bounds[0] = left edge of cell
// bounds[1] = top edge of cell
// bounds[2] = right edge of cell
// bounds[3] = bottom edge of cell
//
var period = 7 * 1000;
var milliseconds = (new Date()).getTime();
var radians = (2 * Math.PI) * ((milliseconds % period) / period);
//
var norm = whichCircle / smcircles.length
var norm2 = whichCircle / whcircles.length
var norm3 = whichCircle / lcircles.length
var frequency = 8;
var frequency2 = 5;
var frequency3 = 6;
var phaseShift = norm * (2 * Math.PI);
var phaseShift2 = norm2 * (2 * Math.PI);
//
smcircles[whichCircle]._x = rangedSin(radians, frequency, phaseShift, bounds[0],
bounds[2]);
smcircles[whichCircle]._y = rangedCos(radians, frequency, phaseShift, bounds[3],
bounds[1]);
whcircles[whichCircle]._x = rangedSin(radians, frequency2, phaseShift2, bounds[0],
bounds[2]);
whcircles[whichCircle]._y = rangedCos(radians, frequency2, phaseShift2, bounds[3],
bounds[1]);
//lcircles[whichCircle]._x = rangedSin(radians, frequency3, phaseShift3, bounds[0],
bounds[2]);
//lcircles[whichCircle]._y = rangedCos(radians, frequency3, phaseShift3, bounds[3],
bounds[1]);
}
//
//
//
//
//
//----------------------------------------------------------------------------------
//
// constants:
var numCols = 3;
var numRows = 3;
var col = Stage.width / numCols;
var row = Stage.height / numRows;
// define an array of references to our circles, for easy addressing
var lcircles = new Array(
largec1, largec2, largec3, largec4, largec5,
largec6, largec7, largec8, largec9, largec10
);
//
var smcircles = new Array(
smc1, smc2, smc3, smc4, smc5, smc6, smc7, smc8,
smc9, smc10, smc11, smc12, smc13
);
var whcircles = new Array(
wc1, wc2, wc3, wc4, wc5, wc6, wc7, wc8, wc9,
wc10
);
//
function updateFrame() {
var curRow = 0;
var curCol = 0;
for (var j = 0; j < smcircles.length; j++) {
var lo_x = (col * curCol) + (.5 * smcircles[j]._width);
var hi_x = (col * (curCol + 1)) - (.5 * smcircles[j]._width);
var lo_y = (row * curRow) + (.5 * smcircles[j]._height);
var hi_y = (row * (curRow + 1)) - (.5 * smcircles[j]._height);
//
curCol++;
if (curCol == numCols) {
curRow++;
curCol = 0;
}
//
circleAnimationstep(j, new Array(lo_x, hi_y, hi_x, lo_y));
}
}
//
function rangedSin(t, f, p, lo, hi) {
var a = (hi - lo) * .5;
var mid = lo + a;
return mid + (a * Math.sin(f * t + p));
}
//
function rangedCos(t, f, p, lo, hi) {
var a = (hi - lo) * .5;
var mid = lo + a;
return mid + (a * Math.cos(f * t + p));
}
//
//
// associate a function with the enterFrame event
this.onEnterFrame = updateFrame;