<script>
var ball = {x:33, y:15, radius:15.0, acceleration:3, velocity:0, friction:0.98, color:"#005588"}
window.onload = function(){
var canvas = document.getElementById('canvas');
canvas.width = 1000;
canvas.height = 250;
var context = canvas.getContext("2d");
setInterval(
function(){
render(context);
update();
},50
)
}
function update(){
ball.x += 2;
ball.y += ball.velocity;
ball.velocity *= ball.friction;
ball.velocity += ball.acceleration;
if(ball.y >= canvas.height - ball.radius){
ball.y = canvas.height - ball.radius;
ball.velocity = - ball.velocity;
}
}
function render(cxt){
cxt.clearRect(0 , 0 , cxt.canvas.width , cxt.canvas.height);
cxt.fillStyle = ball.color;
cxt.beginPath();
cxt.arc(ball.x , ball.y , ball.radius , 0 , 2*Math.PI);
cxt.closePath();
cxt.fill()
}
</script>