Shape drawing function

circle() in graphics.h

circle(int x, int y, int radius);

The circle() function draws the outline of a circle on the active graphics screen. It is one of the first BGI functions students use because it demonstrates the graphics coordinate system clearly: a center point controls position, and a radius controls size. The function does not fill the circle and it does not return a status value. It simply plots the circumference using the current drawing color, line style, and viewport rules.

In practical graphics.h programs, circle() is useful for targets, clock faces, wheels, orbit diagrams, simple logos, and lab assignments that need a quick circular boundary. Because it works from a center point, it is often easier to place than a rectangle. If you know the screen center, you can draw a balanced circle without calculating left and right edges manually.

Parameters

NameTypeDescription
xintThe x-coordinate of the circle center. Larger values move the center toward the right side of the screen.
yintThe y-coordinate of the circle center. Larger values move the center downward because graphics.h uses a top-left screen origin.
radiusintThe circle radius in pixels. A positive radius draws an outline around the center point. Very large radii may extend outside the visible viewport.

All three arguments are integer pixel values. In the usual VGA graphics mode, the top-left coordinate is (0, 0), x increases to the right, and y increases downward. A circle centered at (320, 240) with radius 100 fits nicely on a 640 by 480 screen. A circle centered near an edge can be clipped by the screen boundary, which is normal behavior rather than an error.

Return Value

circle() returns void. It does not tell you whether the circle was visible, clipped, or hidden outside the viewport. If you need startup error handling, check graphresult() after initgraph(). If you need to prevent clipping, calculate the center and radius yourself so that x - radius, x + radius, y - radius, and y + radius stay within the screen or viewport.

Code Examples

Basic centered circle

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

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

    setcolor(YELLOW);
    circle(320, 240, 100);

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

This program opens graphics mode, sets the drawing color to yellow, and draws one circle in the center area of the screen. The output is a clean yellow circular outline on the default background.

Concentric circles

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

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

    for (r = 40; r <= 160; r += 30) {
        setcolor(1 + r / 30);
        circle(320, 240, r);
    }

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

The loop draws several circles around the same center. This produces a target-like pattern and shows how changing only the radius changes the size without moving the shape.

Circle with crosshair lines

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

int main() {
    int gd = DETECT, gm;
    int x = 320, y = 240, r = 90;
    initgraph(&gd, &gm, "");

    setcolor(WHITE);
    circle(x, y, r);
    line(x - r, y, x + r, y);
    line(x, y - r, x, y + r);

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

The output is a circle with horizontal and vertical diameter lines. This is a helpful classroom sketch because it makes the center point, radius, and diameter visible.

Common Mistakes

Forgetting initgraph()

Drawing functions require graphics mode. If initgraph() is missing or fails, circle() cannot display the expected output.

Confusing radius with diameter

The third argument is radius, not diameter. A radius of 100 creates a circle that is about 200 pixels wide.

Using a center too close to the edge

If the center is near a border and the radius is large, part of the circle will be outside the visible screen. Choose a smaller radius or move the center inward.

Expecting a filled circle

circle() draws only an outline. For a filled circular shape, use fillellipse() or combine outlines with fill functions where appropriate.

Try it online

Paste any example into the browser compiler to see the circle rendered without installing Turbo C or configuring BGI paths locally.