These circles wish they looked cooler

Josh Schoenwald
accad 756
task 08: more wave wrangling
10/31/02



//
// Josh Schoenwald *** accad 756 *** task 08 *** 10/31/02 
//



// define a function to perform updates to the stage
function circleAnimationstep(allCircles, curCircle, bigPhaseShift) {
	// define a period of time that will give us a good looking cycle
	var period = 6 * 1000;
	// Date.getTime() returns a large, steadily increasing number
	var milliseconds = (new Date()).getTime();
	// we mod this infinite range by our period to get a range over the time we want,
	// then normalize to get a value in the range [0,1],
	var progress = (milliseconds % period) / period;
	// then scale to the input range of our periodic function [0,2PI]
	var radians = (2 * Math.PI) * progress;
   // now we define our wave controls, starting with default (non-affective) values
	var frequency = 1;

	// xmove and ymove define the path in which the smaller circles will travel, namely in a circle
	var xmove = rangedSin(radians/2, frequency*2, bigPhaseShift, (allCircles[curCircle]._width / 1), ((Stage.width - allCircles[curCircle]._width) * .95));
	var ymove = rangedCos(radians/2, frequency*2, bigPhaseShift, (allCircles[curCircle]._height * .9 ), ((Stage.height - allCircles[curCircle]._height) * .9));

   //defines x movement for the first circle, using cosine and scaled to be visible
	allCircles[curCircle]._x = xmove + rangedCos(radians, frequency*8, phaseShift, (allCircles[curCircle]._width / 16), ((Stage.width - allCircles[curCircle]._width) / 16));
   //defines y movement for the first circle, using sine and scaled to be visible
   allCircles[curCircle]._y = ymove + rangedSin(radians, frequency*8, phaseShift, (allCircles[curCircle]._height / 10), ((Stage.height - allCircles[curCircle]._height) / 10));

   //defines x movement for the second circle, which will run opposite the first circle, so the phase is shifted by PI
   allCircles[curCircle+1]._x = xmove + rangedCos(radians, frequency*8, phaseShift + Math.PI, (allCircles[curCircle]._width / 16), ((Stage.width - allCircles[curCircle]._width) / 16));
   //defines y movement for the second circle, which will run opposite the first circle, so the phase is shifted by PI
   allCircles[curCircle+1]._y = ymove + rangedSin(radians, frequency*8, phaseShift + Math.PI, (allCircles[curCircle]._height / 10), ((Stage.height - allCircles[curCircle]._height) / 10));

   
   //defines the movement for the tiny circles, moving in the large circle but displaced roughly half the difference between the other two circles so it's in the middle
   allCircles[curCircle+2]._x = xmove + (Stage.width / 30);
	allCircles[curCircle+2]._y = ymove + (Stage.height / 21);

   //defines the scaling for the tiny circle, making it tiny
	allCircles[curCircle+2]._xScale = 40;
	allCircles[curCircle+2]._yScale = 40;

   //I used the references of curCircle, Curcircle+1, and +2 to get at the next 2 circles in the array beyond the one passed to the function
	//this is because of how the loop is updated, by j+3 instead of j++ (see loop below)
  
}

//
//----------------------------------------------------------------------------------
//
// constants:
// define an array of references to our circles, for easy addressing
var circles = new Array(circle01, circle02, circle03, circle04, circle05,
								circle06, circle07, circle08, circle09
								);

//phase is used to calculate the shift so that you see 3 sets of 2 orbiting circles
var phase = 0;


function updateFrame() {
	//steps through 3 times at incements of 3, allowing the functions within to call all 9 circles
	for (var j = 0; j < 7; j=j+3) { 
	//calls circleanimationstep to draw the circles in space
   circleAnimationstep(circles, j, phase);
	//the phase is worked out so each set of orbiting circles is equidistant along the period
	phase = phase + ((2 * Math.PI) / 3);
}	

}
//
// ranged sine returns a sine-driven value within the range given
function rangedSin(t, f, p, lo, hi) {
	// t = time (varying value, should range [0,2PI])
	// f = frequency (waves per time, >= 1.0)
	// p = phase shift (affects timing of wave, should range [0,2PI])
	// lo = lower bound of arbitrary range
	// hi = upper bound of arbitrary range
	var a = (hi - lo) * .5;
	var mid = lo + a;
	return mid + (a * Math.sin(f * t + p));
}
//
// ranged cosine returns a cosine-driven value within the range given
function rangedCos(t, f, p, lo, hi) {
	// t = time (varying value, should range [0,2PI])
	// f = frequency (waves per time, >= 1.0)
	// p = phase shift (affects timing of wave, should range [0,2PI])
	// lo = lower bound of arbitrary range
	// hi = upper bound of arbitrary range
	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;





//
// Josh Schoenwald *** accad 756 *** task 08 *** 10/31/02 
//