Bouncing ball simulation I was fooling around with some maths and realized that I could use a parabola to represent a bouncing ball. So, naturally, I decided to make it in code.

var Ball = function(r, v, a, y, x) {
    this.r = r;
    this.v = v;
    this.a = a;
    this.y = y;
    this.x = x;
};

Ball.prototype.draw = function() {
    this.y = this.v*this.r*this.r + this.a*this.r;
    var NewBallY = 380 - this.y;
    ellipse(this.x, NewBallY, 20, 20);
    if(this.y &lt; 0) {
        this.r = 0;}
    this.r += 2;
};

var Ball1 = new Ball(0, random(-0.05, -0.02), random(2.0, 6.0), 40, random(20, 380));
var Ball2 = new Ball(0, random(-0.05, -0.02), random(2.0, 6.0), 40, random(20, 380));
var Ball3 = new Ball(0, random(-0.05, -0.02), random(2.0, 6.0), 40, random(20, 380));

var draw = function() {
    background(255, 255, 255);
    Ball1.draw();
    Ball2.draw();
    Ball3.draw();
};


The equation I used to calculate the parabola representing a ball's \$y\$ position is here, where \$y\$ is the y position of the ball, \$V\$ is the velocity, \$A\$ is the acceleration, and \$r\$ is the amount of time passed since the start of the bounce:

$$y=Vr^{2}+Ar$$
Using this.r to represent elapsed time is highly unconventional.  I would have guessed that r stood for "radius".  Why not use this.t like a sane programmer?

The draw() function ends with this.r += 2;, which is odd.  Why should the drawing routine manage the passage of time?  I would expect the time to be managed either in reference to the wall clock or to be passed in as a parameter by whatever code calls draw().



These don't look like parabolas to me.  At best, they would be degenerate ones, since this.x never changes.



The placement of the closing brace here:

if(this.y &lt; 0) {
    this.r = 0;}


is weird.  Conventional formatting would be:

if (this.y &lt; 0) {
    this.r = 0;
}