I think it's a great way for get a non-programmer interested very quickly, but I personally was quite turned off when I clicked on the "realistic physics" based bouncing ball module and found that the ball doesn't actually stop bouncing, EVER.
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.
I would love to see a modularize Javascript app recorded in this manner that uses the DOM. Maybe a mini 4x4 minecraft game. As someone trying to teach himself , watching the order in which the developer writes would be really enlightening. Regardless, this is a great site.
Indeed they are very similar. Thanks for sharing, though CSSDeck seems to have more samples. Have been procrastinating on learning HTML5/CSS3, this would be great place to start.
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.