Parameters
| Name | Type | Description |
|---|---|---|
x | int | The x-coordinate of the ellipse center. |
y | int | The y-coordinate of the ellipse center. |
stangle | int | The starting angle in degrees. |
endangle | int | The ending angle in degrees. |
xradius | int | The horizontal radius in pixels. Larger values make the ellipse wider. |
yradius | int | The 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.