Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
function drawEllipseParam(ctx, coords, sizes, angle, segments) {
ctx.save();
ctx.translate(coords[0], coords[1]);
ctx.rotate(angle);
ctx.beginPath();
var x, y, firstTime=true;
var dt = 1/segments;
for(var t=0; t<2*Math.PI; t+=dt) {
x = sizes[0]*Math.cos(t);
y = sizes[1]*Math.sin(t);
if(firstTime) {
firstTime = false;
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
}
ctx.strokeStyle = 'blue';
ctx.stroke();
ctx.closePath();
ctx.restore();
}
ctx.rotate(0.3);
ctx.save();
ctx.translate(50, 50);
ctx.scale(0.75, 1);
ctx.arc(0, 0, 50, 0, Math.PI*2, false);
ctx.closePath();
ctx.stroke();
ctx.restore();
ctx.rotate(-0.3);
ctx.scale(0.1, 1);
ctx.save();
ctx.fillStyle = 'red';
ctx.translate(100, 100);
ctx.rotate(30 * Math.PI / 180);
ctx.scale(0.75, 1);
ctx.translate(-100, -100);
ctx.arc(100, 100, 50, 0, Math.PI*2, true);
ctx.fill();
ctx.restore();
Рисование эллипса под произвольным углом в canvas на JavaScript