You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
858 B
38 lines
858 B
2 years ago
|
|
||
|
|
||
|
function BallSwing(fulcrumx, fulcrumy, ballx, bally, r){
|
||
|
|
||
|
x = ballx - fulcrumx;
|
||
|
y = bally - fulcrumy;
|
||
|
this.poleLen = Math.sqrt(x*x + y*y);
|
||
|
this.fx = fulcrumx;
|
||
|
this.fy = fulcrumy;
|
||
|
this.bx = ballx;
|
||
|
this.by = bally;
|
||
|
this.dx = 0;
|
||
|
this.dy = 0;
|
||
|
|
||
|
this.update = function(){
|
||
|
x = this.bx - this.fx;
|
||
|
y = this.by - this.fy;
|
||
|
realLen = Math.sqrt(x*x + y*y);
|
||
|
nx = x/realLen;
|
||
|
ny = y/realLen;
|
||
|
this.dy += 1;
|
||
|
s = this.dx * nx + this.dy * ny;
|
||
|
this.dx -= s*nx;
|
||
|
this.dy -= s*ny;
|
||
|
dlen = this.poleLen - realLen;
|
||
|
this.dx += dlen * nx;
|
||
|
this.dy += dlen * ny;
|
||
|
this.bx += this.dx;
|
||
|
this.by += this.dy;
|
||
|
};
|
||
|
|
||
|
this.draw = function(){
|
||
|
line(this.fx, this.fy, this.bx, this.by)
|
||
|
circle(this.bx, this.by, r)
|
||
|
};
|
||
|
|
||
|
}
|