
Elipsa
Elipsę można wykreślić korzystając z równania parametrycznego:

gdzie:
a – to duża oś elipsy
b – to mała oś elipsy
t – zawiera się w przedziale <0,2π)
Listing
var drawOval = function(x, y, w, h, liczbaPunktow, strokeStyle) {
var a = w / 2;
var b = h / 2;
ctx.save();
ctx.beginPath();
ctx.strokeStyle = strokeStyle;
ctx.translate(x + a, y + b);
var x2;
var y2;
for ( var i = 0; i < liczbaPunktow; i++) {
var t = i * Math.PI / 360;
x2 = a * Math.cos(t);
y2 = b * Math.sin(t);
ctx.lineTo(Math.floor(x2), Math.floor(y2));
}
ctx.stroke();
ctx.restore();
};
var cv = document.getElementById("canvas");
var ctx = cv.getContext("2d");
var w = cv.width;
var h = cv.height;
drawOval(100, 100, 100, 70, 1000, "orange");
