//Move VISAGE/Helix and Rebound/Cool for an installation
//Marlon Barrios Solano
//This the rebound version
//declare all the variables for all the movies
var xDir = 1;
var yDir = 1;
var xDir2 = .8;
var yDir2= .8;
var xDir3= .6;
var yDir3= .6;
var maxSpeed =20;
var maxSpeed2 = 30;
var maxSpeed3 = 30;
var speed = new Array(newSpeed(maxSpeed), newSpeed(maxSpeed));
var speed2 = new Array (newSpeed(maxSpeed2),newSpeed (maxSpeed2));
var speed3 = new Array (newSpeed(maxSpeed3),newSpeed (maxSpeed3));
var radius = circle._width * .5;
var radius2= circle2._width * .5;
var radius3= circle3._width * .5;
var t = 0;
//
//
//to count----
function updateFrame() {
t = (t + .01) % (Math.PI * 2);
circle._x += speed[0] * xDir;
circle._y += speed[1] * yDir;
circle2._x += speed[0] * xDir2;
circle2._y += speed[1] * yDir2;
circle3._x += speed[0] * xDir3;
circle3._y += speed[1] * yDir3;
//movies 1,2,3
//side bounds
if (circle._x < radius) {
circle._x = radius;
xDir *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle._x > Stage.width - radius) {
circle._x = Stage.width - radius;
xDir *= -1;
speed[0] = newSpeed(maxSpeed);
}
//top and bottom bounds/same for the other movies
if (circle._y < radius) {
circle._y = radius;
yDir *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle._y > Stage.height - radius) {
circle._y = Stage.height - radius;
yDir *= -1;
speed[1] = newSpeed(maxSpeed);
}
////////////////////
if (circle2._x < radius) {
circle2._x = radius;
xDir2 *= -1;
speed2[0] = newSpeed(maxSpeed2);
}
else if (circle2._x > Stage.width - radius) {
circle2._x = Stage.width - radius;
xDir2 *= -1;
speed2[0] = newSpeed(maxSpeed2);
}
if (circle2._y < radius) {
circle2._y = radius;
yDir2 *= -1;
speed2[1] = newSpeed(maxSpeed2);
}
else if (circle2._y > Stage.height - radius) {
circle2._y = Stage.height - radius;
yDir2 *= -1;
speed2[1] = newSpeed(maxSpeed2);
}
/////////////////////////
if (circle3._x < radius) {
circle3._x = radius;
xDir3 *= -1;
speed3[0] = newSpeed(maxSpeed3);
}
else if (circle3._x > Stage.width - radius) {
circle3._x = Stage.width - radius;
xDir3 *= -1;
speed3[0] = newSpeed(maxSpeed3);
}
if (circle3._y < radius) {
circle3._y = radius;
yDir3 *= -1;
speed3[1] = newSpeed(maxSpeed3);
}
else if (circle3._y > Stage.height - radius) {
circle3._y = Stage.height - radius;
yDir3 *= -1;
speed3[1] = newSpeed(maxSpeed3);
}
}//close the conditions
//
//
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;
//
//
// 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));
}