Draw Ellipse - Node.js HTML

Node.js examples for HTML:Canvas

Description

Draw Ellipse

Demo Code


if (CanvasRenderingContext2D.prototype.drawEllipse === undefined) {
    CanvasRenderingContext2D.prototype.drawEllipse = function drawEllipse(centerX, centerY, w, h) {
        this.beginPath();//from w w w  .  j a  v a2s  .  c  o m
        var lx = centerX - w / 2,
            rx = centerX + w / 2,
            ty = centerY - h / 2,
            by = centerY + h / 2;
        var magic = 0.551784;
        var xmagic = magic * w / 2;
        var ymagic = h * magic / 2;
        this.moveTo(centerX, ty);
        this.bezierCurveTo(centerX + xmagic, ty, rx, centerY - ymagic, rx, centerY);
        this.bezierCurveTo(rx, centerY + ymagic, centerX + xmagic, by, centerX, by);
        this.bezierCurveTo(centerX - xmagic, by, lx, centerY + ymagic, lx, centerY);
        this.bezierCurveTo(lx, centerY - ymagic, centerX - xmagic, ty, centerX, ty);
    };
}

Related Tutorials