I'm trying to completely clear a canvas in JavaScript. But if I add a vertical text (rotating the canvas) and then call context.clearRect(0, 0, canvas.width, canvas.height) the text remains.
I don't want to use canvas.width = canvas.width or delete the canvas and create a new one.
My code:
var canvas = document.getElementById("canvas");
var c = canvas.getContext("2d");
verticalText("text", 0, 0, 20, "Arial");
c.clearRect(0, 0, canvas.width, canvas.height);
function verticalText(text, x, y, dim, font) {
c.font = dim + "px " + font;
var size = c.measureText(text);
var tx = canvas.width / 2 + dim / 2.5;
var ty = canvas.height / 2 - dim / 2.5;
c.save();
c.translate(tx,ty);
c.rotate(-Math.PI / 2);
c.translate(-tx,-ty);
c.fillText(text, canv.height - y - size.width, x);
c.restore();
}
What should I do?