Been working with HTML 5 recently and I ran into a very frustrating problem.
Using CSS to set the width and height of a canvas element stretches the content inside to the new width/height that you set.
Example 1 (will stretch):
this.canvas.setAttribute('width', w);
this.canvas.setAttribute('height', h);
To simply resize the area of the canvas element, do this:
this.canvas.width = w; this.canvas.height = h;