Curve drawing function

ellipse() in graphics.h

ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);

The ellipse() function draws an elliptical outline or an elliptical arc. It is similar to arc(), but it uses two radii instead of one: a horizontal radius and a vertical radius. When both radii are equal, the result behaves like a circle or circular arc. When they differ, the result becomes an oval. This makes ellipse() useful for planets, wheels viewed from an angle, faces, lenses, buttons, shadows, or any shape that needs a stretched curve.

The function accepts start and end angles in degrees. Like arc(), 0 degrees points to the right, 90 points upward, 180 points left, and 270 points downward. With stangle = 0 and endangle = 360, you draw a complete ellipse. With smaller angle ranges, you draw only part of the oval.

Parameters

NameTypeDescription
xintThe x-coordinate of the ellipse center.
yintThe y-coordinate of the ellipse center.
stangleintThe starting angle in degrees.
endangleintThe ending angle in degrees.
xradiusintThe horizontal radius in pixels. Larger values make the ellipse wider.
yradiusintThe vertical radius in pixels. Larger values make the ellipse taller.

The center and radii define the bounding region. A full ellipse centered at (320, 240) with xradius = 160 and yradius = 80 stretches from x = 160 to x = 480, and from y = 160 to y = 320. This mental calculation helps you keep the shape on screen.

Return Value

ellipse() returns void. It does not return a bounding box or tell you whether the shape was clipped. If the ellipse is partly outside the screen, only the visible portion appears. For reliable diagrams, keep x - xradius, x + xradius, y - yradius, and y + yradius inside the screen limits.

Code Examples

Full ellipse

#include <graphics.h>
#include <conio.h>

int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");

    setcolor(LIGHTCYAN);
    ellipse(320, 240, 0, 360, 160, 80);

    getch();
    closegraph();
    return 0;
}

The output is a wide oval centered on the screen. The horizontal radius is twice the vertical radius, so the ellipse is wider than it is tall.

Partial ellipse arc

#include <graphics.h>
#include <conio.h>

int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");

    setcolor(YELLOW);
    ellipse(320, 250, 20, 160, 180, 90);
    line(150, 250, 490, 250);

    getch();
    closegraph();
    return 0;
}

This draws the upper curved portion of an ellipse with a guide line through the center. It is a good way to see how angle limits affect the visible part of the oval.

Simple planet with rings

#include <graphics.h>
#include <conio.h>

int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");

    setcolor(WHITE);
    circle(320, 240, 70);
    setcolor(LIGHTGREEN);
    ellipse(320, 240, 0, 360, 160, 42);
    ellipse(320, 240, 0, 360, 180, 52);

    getch();
    closegraph();
    return 0;
}

The output is a circle with two wide ellipses passing around it, forming a basic ringed planet. This combines circle() and ellipse() in one drawing.

Common Mistakes

Using one radius value mentally

ellipse() has separate horizontal and vertical radii. If you expect a circle but use different values, the output will be stretched.

Mixing up xradius and yradius

xradius controls width and yradius controls height. Swapping them changes a wide ellipse into a tall ellipse.

Forgetting to use 0 to 360 for a full ellipse

If you provide a smaller angle range, only part of the ellipse is drawn. Use 0, 360 when you want the entire outline.

Expecting a filled oval

ellipse() draws an outline. Use fillellipse() when a filled oval is required.

Try it online

Paste an example into the compiler and experiment with xradius, yradius, and angle values. Ellipse behavior becomes intuitive once you see the shape stretch live.