See https://developer.mozilla.org/en/Canvas_tutorial/Basic_animations#An_animation_example_2 for canvas tutorial.