Some P5 sketches I made.
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.
 

37 lines
858 B

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)
};
}