Andrew Poulos wrote:
Is there a right/best way to draw an ellipse using Canvas? (With VML
there's the v:oval element which makes the exercise trivial). I tried
drawing a 360 degree arc (a circle) and then scaling it but that also
scales the thickness of the circumference.
This example
function addEllipsePath (context, cx, cy, r1, r2, startAngle, endAngle) {
context.save();
context.translate(cx, cy);
context.scale(r1, r2);
context.arc(0, 0, 1, startAngle, endAngle, 0);
context.restore();
}
var canvas = document.createElement('canvas');
canvas.width = 300;
canvas.height = 300;
canvas.style.border = '1px solid green';
document.body.appendChild(canvas);
var context = canvas.getContext('2d');
context.strokeStyle = 'rgba(255, 0, 0, 1)';
addEllipsePath(context, 150, 150, 30, 60, 0, Math.PI * 2);
context.lineWidth = 3;
context.stroke();
works for me with Firefox 1.5 on Windows, but Opera 9.02 does not show
the ellipse. Please report back whether it works with Safari.
The idea of the above approach was taken from
<http://www.redgrittybrick.org/postscript/respectively
<http://www.redgrittybrick.org/postscript/ellipse.htmlwhich talks
about doing ellipses with Postscript.
--
Martin Honnen
http://JavaScript.FAQTs.com/