Task 08

martin voshell

flow patterns attempted to be mimicked


//Task 08
// martin voshell


// attempt to model the motion of nitrogen heavy liquid in guinness
// heavy nitrogen goes up and pulls liquid with it, then falls
// on sides, falls more readily



//this mimicks the upward motion of the larger particles



//set up first function to model the up and down shifts
function circleAnimationstep(whichCircle, bounds) {

var period = 100 * 1000;
var milliseconds = (new Date()).getTime();
var progress = (milliseconds % period) / period;
var radians = (2 * Math.PI) * progress;
var frequency = 1;
var norm = whichCircle / circles.Length;
var phaseShift = norm * (2 * Math.PI);



// call a tangent function to model the vertical shifting of the particles
circles[whichCircle]._y = rangedTan(radians, frequency, phaseShift, bounds[1], bounds[2]);

//fade the bubbles quickly
circles[whichCircle]._alpha = fader(radians, frequency*2, phaseShift, 0, 30);

//make the rising and falling large in scale to help simulate ligquid wave pattern
circles[whichCircle]._xscale = rangedSin(radians, frequency, phaseShift, 100, 700);
circles[whichCircle]._yscale = rangedSin(radians, frequency, phaseShift, 100, 700);


}






//small beer imitates the two "central" rings of falling nitrogen

function smallbeer(allCircles, curCircle) {

// have to set up constants again for this function
// want it much quicker than the large one

var period = 10 * 1000;
var milliseconds = (new Date()).getTime();
//period repeats
var progress = (milliseconds % period) / period;
var radians = (2 * Math.PI) * progress;

var norm = curCircle / allCircles.Length;
var frequency = 1;
//apply to the expected input range for our periodic function and assign to our phaseShift
var phaseShift = norm * (2 * Math.PI);


//move the inner loop in an elliptical fashion
allCircles[curCircle]._x = rangedSin(radians, frequency*2, phaseShift*4, allCircles[curCircle]._width, Stage.width - allCircles[curCircle]._width);
//keep phases different so don't have one ring in the center
allCircles[curCircle]._y = rangedCos(radians, frequency*2, phaseShift*2, allCircles[curCircle]._height, Stage.height - allCircles[curCircle]._height);

//scale the bubbles slightly for aesthetics
allCircles[curCircle]._xscale = rangedSin(radians,frequency,phaseShift,50,100);
allCircles[curCircle]._yscale = rangedSin(radians,frequency,phaseShift,50,100);


}



//
//
//
//
//
//----------------------------------------------------------------------------------
//
// using Peter's array row x col scheme... faster when have two update for loops

var numCols = 5;
var numRows = 5;
var col = Stage.width / numCols;
var row = Stage.height / numRows;

//create an array for the circles referenced via an array of rows and columns

var circles = new Array(circle01, circle02, circle03, circle04, circle05, circle06,
circle07, circle08, circle09, circle10, circle11, circle12, circle13, circle14,
circle15, circle16, circle17, circle18, circle19, circle20, circle21, circle22,
circle23, circle24, circle25);


// create an array for my central small bubbles
var leftmini = new Array(circlec1, circlec2, circlec3, circlec4, circlec5, circlec6, circlec7, circlec8, circlec9,circlec10, circlec11, circlec12, circlec13, circlec14, circlec15, circlec16, circlec17, circlec18);




//
//
// originally went through two for loops and then updates frame
// first passes location and second passes boxes, to respective functions

function updateFrame() {
var curRow = 0;
var curCol = 0;



for (var j = 0; j < circles.length; j++) {
var lo_x = (col * curCol) + (.5 * circles[j]._width);
var hi_x = (col * (curCol + 1)) - (.5 * circles[j]._width);
var lo_y = (row * curRow) + (.5 * circles[j]._height);
var hi_y = (row * (curRow + 1)) - (.5 * circles[j]._height);
//

curCol++;
if (curCol == numCols) {
curRow++;
curCol = 0;
}


//pass incr'd to respective functions
circleAnimationstep(j, new Array(lo_x, hi_y, hi_x, lo_y));
smallbeer(leftmini, j);
}

}



// define multiple wave functions to model


// cos(-x)
function rangedNCos(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((-1*(f * t + p))));
}


// sin (-x)
function rangedNSin(t, f, p, lo, hi) {
var a = (hi - lo) * .5;
var mid = lo + a;
return mid + (a * Math.sin((-1*(f * t + p))));
}



// return sin value over a range
function rangedSin(t, f, p, lo, hi) {
var a = (hi - lo) * .5;
var mid = lo + a;
return mid + (a * Math.sin(f * t + p));
}


//return cos value over a range
function rangedCos(t, f, p, lo, hi) {
var a = (hi - lo) * .5;
var mid = lo + a;
return mid + (a * Math.cos(f * t + p));
}



//return tan values over a range
function rangedTan(t, f, p, lo, hi) {
var a = (hi - lo) * .5;
var mid = lo + a;
return mid + (a * Math.tan(f * t + p)*-1);
}




//fade the alpha over a range
function fader(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));

}





//
//
// update the stage and keep on truckin'
this.onEnterFrame = updateFrame;
//