Curve drawing function

arc() in graphics.h

arc(int x, int y, int stangle, int endangle, int radius);

The arc() function draws part of a circle. You provide a center point, a starting angle, an ending angle, and a radius. Instead of drawing a full circumference like circle(), it draws only the circular section between the two angle values. This makes it useful for speedometers, gauges, smile curves, circular progress drawings, pie-chart outlines, clock marks, and diagrams where only a portion of a circle should be visible.

Angles in graphics.h are measured in degrees, with 0 degrees pointing to the right, like the 3 o'clock position on a clock. The angle increases counter-clockwise: 90 points upward, 180 points left, and 270 points downward. This convention is one of the most important things to remember when using arc(), because it differs from how the screen y-axis grows downward.

Parameters

NameTypeDescription
xintThe x-coordinate of the arc center.
yintThe y-coordinate of the arc center.
stangleintThe starting angle in degrees. Zero degrees is the right side of the circle.
endangleintThe ending angle in degrees. The arc is drawn counter-clockwise from the start angle to this value.
radiusintThe radius of the circular arc in pixels.
Quick angle guide: 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.