CSSDeck Codecasts: Learn HTML5, CSS3, Javascript in a new way
cssdeck.com
cssdeck.com
The problem occurs in the following code:
if(ball.y + ball.radius > H) { // First, reposition the ball on top of the floor and then bounce it! ball.y = H - ball.radius; ball.vy *= -bounceFactor; // The bounceFactor variable that we created decides the elasticity or how elastic the collision will be. If it's 1, then the collision will be perfectly elastic. If 0, then it will be inelastic. }
Basically, when the ball hits the ground (the collision check), it should no longer be receiving a gravity modifier as it's "on the ground". Additionally, because there's a user set velocity variable, there needs to be a check against the crest of bounce to slowly reduce that variable down to 0 so the ball will stay stationary.
Call me a stickler, but seeing a "physics" demo no matter how loosely it's based get stuck in an infinite bounce just rubs me the wrong way.