More or less a straight port of the andriod.graphics version to HTML5.