Javascript programming - the bouncing ball
I did this bouncing ball simulation (with clouds and gravity) using just javascript. I also played with CSS3, so this doesn't work well on IE. It's fine on Firefox, Chrome, and should be fine on Safari and any webkit browser.
http://clankiller.com/stuff/bounce/The clouds are dynamically generated objects the grab a random height, random speed and random direction, then fade in, scroll until they hit the end of the screen, and fade out. The master script controls the fade out, destroys the cloud object when it's done, and creates a new one. Fun stuff, but not actually all that hard.
The bouncing ball was a lot harder. Be advised you can click-grab the ball and throw it. That part was a lot of fun. Not so much fun was calculating the arc and speed of the ball. I hacked a gravity approximation, but it's poorly implemented... I basically subtract from the speed due to gravity, rather than just the vertical component of the speed. Trying to fix that has mostly caused me to just violate the laws of physics with flubber-like balls that gain speed instead of lose it.
Oh, and if you throw the ball and it gets "stuck" on your pointer, just left click on the ball to drop it, then right-click on the background. I don't know why it happens, I really don't, or I'd fix it.
So, anyway, anyone that actually read this, please play with the page and enjoy. If you want to try your hand at fixing the physics, this is why it's in the programming forum. Here's the gravity/physics code for the ball object. This code block is executed every 25ms.
Most of the below should be fairly intelligible. that.speed refers to the speed of the ball object. that.vector is the vector of the ball object... more correctly it's the angle, with 0 being right, 90 being up, 180 being left, and 270 being down. tools.getlocation is from my javascript tools script, and it just gets the top and left of the object in question in pixels. gravity is a constant that I believe I have set to 9.8. There's also some code in there to make the ball flex when it hits the ground, but you can barely see it, so I'm not sure it's worth the code. *shrug*
I'm interested in any feedback, be it programming or physics related... or anything else, really. I am pretty much done messing with this, but that doesn't mean I won't make a similar physics experiment in the future and I could well benefit from good advice.