//
adds force in X and Y to spring for ETdots[i] on ETdots[j]
function ETspringForce(i, j, spring) {
var dx = (ETdots[i].X - ETdots[j].X);
var dy = (ETdots[i].Y - ETdots[j].Y);
var len = Math.sqrt(dx*dx + dy*dy);
if (len > ETsegLen) {
var springF = ETspringK * (len - ETsegLen);
spring.X += (dx / len) * springF;
spring.Y += (dy / len) * springF;}
}function ETanimate() {
// ETdots[0] follows the mouse, though no dot is
drawn there
var start = 0;
if (ETfollowMouse) {
ETdots[0].X = Xmouse;
ETdots[0].Y = Ymouse;
start = 1;}
for (i = start ; i < ETnDots; i++ ) {
var spring = new vector(0, 0);
if (i > 0) {
ETspringForce(i-1, i, spring);}
if (i < (ETnDots - 1)) {
ETspringForce(i+1, i, spring);}
// air resisitance/friction
var resist = new vector(-ETdots[i].dx
* ETresistance,
-ETdots[i].dy *
ETresistance);
// compute new accel,
including gravity
var accel = new vector((spring.X +
resist.X)/ ETmass,
(spring.Y +
resist.Y)/ ETmass + ETgravity);
// compute new velocity
ETdots[i].dx += (ETdeltaT * accel.X);
ETdots[i].dy += (ETdeltaT * accel.Y);
// stop dead so it doesn't
jitter when nearly still
if (Math.abs(ETdots[i].dx) < ETstopVel
&&
Math.abs(ETdots[i].dy) <
ETstopVel &&
Math.abs(accel.X) < ETstopAcc &&
Math.abs(accel.Y) < ETstopAcc) {
ETdots[i].dx = 0;
ETdots[i].dy =
0;}
// move to new position
ETdots[i].X += ETdots[i].dx;
ETdots[i].Y += ETdots[i].dy;
// get size of window
var height, width;
if (isNetscape) {
height =
window.innerHeight + document.scrollTop;
width =
window.innerWidth + document.scrollLeft;}
else {
height =
document.body.clientHeight + document.body.scrollTop;
width =
document.body.clientWidth + document.body.scrollLeft;}
// bounce of 3 walls (leave
ceiling open)
if (ETdots[i].Y >= height -
ETdotSize - 1) {
if (ETdots[i].dy
> 0) {
ETdots[i].dy = ETbounce * -ETdots[i].dy;}
ETdots[i].Y =
height - ETdotSize - 1;}
if (ETdots[i].X >= width - ETdotSize) {
if (ETdots[i].dx
> 0) {
ETdots[i].dx = ETbounce * -ETdots[i].dx;}
ETdots[i].X =
width - ETdotSize - 1;}
if (ETdots[i].X < 0) {
if (ETdots[i].dx
< 0) {
ETdots[i].dx = ETbounce * -ETdots[i].dx;}
ETdots[i].X = 0;}
// move img to new position
ETdots[i].obj.left = ETdots[i].X;
ETdots[i].obj.top = ETdots[i].Y;
}
}