Task 09

 

********************************

// circle variables: each have different xDir, yDir, and radius variables

//circle1
var xDir = 1.5;
var yDir = 1.5;

//circle2

var xDir2 = 2.5;
var yDir2 = -3;

//circle3

var xDir3 = -3;
var yDir3 = 2;

//circle4

var xDir4 = -1;
var yDir4 = 1.5;

//circle5

var xDir5 = -1;
var yDir5 = 3;

//circle6

var xDir6 = -2;
var yDir6 = 2.5;

//circle7

var xDir7 = -3;
var yDir7 = 2.5;

//circle8

var xDir8 = 1.5;
var yDir8 = 1.5;

//circle9

var xDir9 = 1.5;
var yDir9 = 1.5;

//circle10

var xDir10 = -1;
var yDir10 = 2;

//circle11

var xDir11 = -1;
var yDir11 = 2;

//circle12

var xDir12 = -1;
var yDir12 = 2;

var maxSpeed = 20;

var speed = new Array(newSpeed(maxSpeed), newSpeed(maxSpeed));

var radius = circle._width * .5;
var radius = circle2._width * .5;
var radius = circle3._width * .5;
var radius = circle4._width * .5;
var radius = circle5._width * .5;
var radius = circle6._width * .5;
var radius = circle7._width * .5;
var radius = circle8._width * .5;
var radius = circle9._width * .5;
var radius = circle10._width * .5;
var radius = circle11._width * .5;
var radius = circle12._width * .5;
//
//
////////////////////////////////////////////////////////////////

// function below is for all circles: all have if/elseif statements (probably should have looped ..but didn't!)
function updateFrame() {
// circle 1
circle._x += speed[1] * xDir;
circle._y += speed[1] * yDir;
//
//
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);
}
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);
}

//circle2
circle2._x += speed[1] * xDir2;
circle2._y += speed[1] * yDir2;
//

if (circle2._x < radius) {
circle2._x = radius;
xDir2 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle2._x > Stage.width - radius) {
circle2._x = Stage.width - radius;
xDir2 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle2._y < radius) {
circle2._y = radius;
yDir2 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle2._y > Stage.height - radius) {
circle2._y = Stage.height - radius;
yDir2 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle3
circle3._x += speed[1] * xDir3;
circle3._y += speed[1] * yDir3;
//

if (circle3._x < radius) {
circle3._x = radius;
xDir3 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle3._x > Stage.width - radius) {
circle3._x = Stage.width - radius;
xDir3 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle3._y < radius) {
circle3._y = radius;
yDir3 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle3._y > Stage.height - radius) {
circle3._y = Stage.height - radius;
yDir3 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle4
circle4._x += speed[1] * xDir4;
circle4._y += speed[1] * yDir4;
//

if (circle4._x < radius) {
circle4._x = radius;
xDir4 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle4._x > Stage.width - radius) {
circle4._x = Stage.width - radius;
xDir4 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle4._y < radius) {
circle4._y = radius;
yDir4 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle4._y > Stage.height - radius) {
circle4._y = Stage.height - radius;
yDir4 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle5
circle5._x += speed[1] * xDir5;
circle5._y += speed[1] * yDir5;
//

if (circle5._x < radius) {
circle5._x = radius;
xDir5 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle5._x > Stage.width - radius) {
circle5._x = Stage.width - radius;
xDir5 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle5._y < radius) {
circle5._y = radius;
yDir5 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle5._y > Stage.height - radius) {
circle5._y = Stage.height - radius;
yDir5 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle6
circle6._x += speed[1] * xDir6;
circle6._y += speed[1] * yDir6;
//

if (circle6._x < radius) {
circle6._x = radius;
xDir6 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle6._x > Stage.width - radius) {
circle6._x = Stage.width - radius;
xDir6 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle6._y < radius) {
circle6._y = radius;
yDir6 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle6._y > Stage.height - radius) {
circle6._y = Stage.height - radius;
yDir6 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle7
circle7._x += speed[1] * xDir7;
circle7._y += speed[1] * yDir7;
//

if (circle7._x < radius) {
circle7._x = radius;
xDir7 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle7._x > Stage.width - radius) {
circle7._x = Stage.width - radius;
xDir7 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle7._y < radius) {
circle7._y = radius;
yDir7 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle7._y > Stage.height - radius) {
circle7._y = Stage.height - radius;
yDir7 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle8
circle8._x += speed[1] * xDir8;
circle8._y += speed[1] * yDir8;
//

if (circle8._x < radius) {
circle8._x = radius;
xDir8 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle8._x > Stage.width - radius) {
circle8._x = Stage.width - radius;
xDir8 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle8._y < radius) {
circle8._y = radius;
yDir8 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle8._y > Stage.height - radius) {
circle8._y = Stage.height - radius;
yDir8 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle9
circle9._x += speed[1] * xDir9;
circle9._y += speed[1] * yDir9;
//

if (circle9._x < radius) {
circle9._x = radius;
xDir9 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle9._x > Stage.width - radius) {
circle9._x = Stage.width - radius;
xDir9 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle9._y < radius) {
circle9._y = radius;
yDir9 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle9._y > Stage.height - radius) {
circle9._y = Stage.height - radius;
yDir9 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle10
circle10._x += speed[1] * xDir10;
circle10._y += speed[1] * yDir10;
//

if (circle10._x < radius) {
circle10._x = radius;
xDir10 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle10._x > Stage.width - radius) {
circle10._x = Stage.width - radius;
xDir10 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle10._y < radius) {
circle10._y = radius;
yDir10 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle10._y > Stage.height - radius) {
circle10._y = Stage.height - radius;
yDir10 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle11
circle11._x += speed[1] * xDir11;
circle11._y += speed[1] * yDir11;
//

if (circle11._x < radius) {
circle11._x = radius;
xDir11 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle11._x > Stage.width - radius) {
circle11._x = Stage.width - radius;
xDir11 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle11._y < radius) {
circle11._y = radius;
yDir11 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle11._y > Stage.height - radius) {
circle11._y = Stage.height - radius;
yDir11 *= -1;
speed[1] = newSpeed(maxSpeed);
}

//circle12
circle12._x += speed[1] * xDir12;
circle12._y += speed[1] * yDir12;
//

if (circle12._x < radius) {
circle12._x = radius;
xDir12 *= -1;
speed[0] = newSpeed(maxSpeed);
}
else if (circle12._x > Stage.width - radius) {
circle12._x = Stage.width - radius;
xDir12 *= -1;
speed[0] = newSpeed(maxSpeed);
}
if (circle12._y < radius) {
circle12._y = radius;
yDir12 *= -1;
speed[1] = newSpeed(maxSpeed);
}
else if (circle12._y > Stage.height - radius) {
circle12._y = Stage.height - radius;
yDir12 *= -1;
speed[1] = newSpeed(maxSpeed);
}
}
//
//
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));
}