window.requestAnimationFrame = function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.setTimeout(f,1e3/60);
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d'),
window_width = window.innerWidth,
window_height = window.innerHeight,
canvas.width = window_width;
canvas.height = window_height;
platform.x = (window_width / 2) - (platform.width / 2);
platform.y = (window_height - 50);
ctx.fillStyle = platform.color;
ctx.fillRect(platform.x, platform.y, platform.width, platform.height);
ball.x = (window_width / 2);
ctx.fillStyle = ball.color;
ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI*2, false);
ctx.clearRect(0, 0, window_width, window_height);
then = new Date().getTime(),
function f2T(Delta, Speed) {
return (Speed * Delta) * (60 / 1000);
fps = 30 + Math.random() * 30;
now = new Date().getTime();
ball.y += f2T(delta, ball.vy);
ball.vy += f2T(delta, gravity);
var speed = ball.vy + gravity,
distance = platform.y - (ball.y + ball.radius),
if(time > 0 && time < f2T(delta, 1)) {
ball.y = platform.y - ball.radius;
requestAnimationFrame(animloop);