Parameters
| Name | Type | Description |
|---|---|---|
x | int | The x-coordinate of the arc center. |
y | int | The y-coordinate of the arc center. |
stangle | int | The starting angle in degrees. Zero degrees is the right side of the circle. |
endangle | int | The ending angle in degrees. The arc is drawn counter-clockwise from the start angle to this value. |
radius | int | The radius of the circular arc in pixels. |
arc(320, 240, 0, 180, 100) draws the upper half of a circle. arc(320, 240, 180, 360, 100) draws the lower half.Return Value
arc() returns void. It does not return the arc length, endpoint coordinates, or clipping state. If you need to label the endpoints of an arc, calculate them from the center, radius, and angles using trigonometry, or draw guide lines while testing.
Code Examples
Upper semicircle
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(YELLOW);
arc(320, 240, 0, 180, 120);
getch();
closegraph();
return 0;
}
The output is the upper half of a circle. The arc begins at the right side of the circle and travels counter-clockwise to the left side.
Gauge outline
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(LIGHTGREEN);
arc(320, 300, 30, 150, 160);
arc(320, 300, 30, 150, 120);
line(320, 300, 410, 220);
getch();
closegraph();
return 0;
}
This draws two curved gauge boundaries and one needle line. It resembles a simple meter. The two arcs share the same center and angles but use different radii.
Smile curve
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(WHITE);
circle(320, 240, 120);
circle(275, 210, 12);
circle(365, 210, 12);
arc(320, 245, 200, 340, 70);
getch();
closegraph();
return 0;
}
The output is a simple face. The mouth is an arc from 200 to 340 degrees, which creates a smile-shaped curve near the bottom of the face.
Common Mistakes
Using radians instead of degrees
arc() expects degrees. Values like 3.14 are not meaningful here, and the function parameters are integers.
Forgetting the angle direction
Angles increase counter-clockwise from the right side. If your arc appears in the opposite half of the circle, check the start and end angle values first.
Expecting a filled sector
arc() draws only the curved outline. Use pieslice() or fill functions if you need a filled circular sector.
Confusing arc() with ellipse()
arc() uses one radius and always follows a circle. Use ellipse() when the horizontal and vertical radii need to be different.
Try it online
Run the examples and change only the start and end angles. You will quickly build a mental map of where 0, 90, 180, and 270 degrees land on the graphics screen.