Completed Example 2 in HTML5 Canvas