How to Use fillellipse() Function in C Programing Language

fillellipse() function using C or C++ programing language

Introduction :

One of the essential functions of graphics.h library is fillellipse() function. The fillellipse() function enables you to draw ellipse with filled color on the screen. The graphics.h is useful for learning basic concept of graphics using C or C++ programing language. The fillellipse() function is part of the graphics.h library, which is a non-standard library specific to the Turbo C++ compiler.

In this article, I shall discuss you how to use the fillellipse() function by C or C++ programing language. Here you learn the use of fillellipse() function of graphics.h library in Turbo C++ IDE. If you want to use fillellipse() function, you have to install Turbo C++ on your pc.

The fillellipse() function is a valuable tool for simple graphics programming which is used to create different effects and animations. The fillellipse() function can be used in different ways, depending on the specific requirements of your program. Here, I show you some different usages of the fillellipse() function of graphics.h library by C or C+ programing language.

Syntax of the fillellipse() function :

The fillellipse() function in the graphics.h library is used to draw a filled ellipse on the screen. It takes the center coordinates, horizontal radius, and vertical radius of the ellipse as its parameters.

The following syntax is used for fillellipse() function of graphics.h library in C or C++ programing language.

void fillellipse(int x, int y, int x_radius, int y_radius);

The fillellipse() function of graphics.h library takes four parameters. The x and y represent the x-coordinate and y-coordinate of the center of the ellipse. The x_radius represents the horizontal radius of the ellipse. The x_radius define how far the ellipse extends from center point to left and right sides. The y_radius represents the vertical radius of the ellipse. The y_radius define how far the ellipse extends from center point to the top and bottom.

The fillellipse() function is used to draw a filled ellipse on the screen using the default fill style. You can change the color or pattern by using the setfillstyle() function.

How to run the program :

If you run the program on your pc, first install Turbo C++ on your pc because graphics.h is a popular header file of Turbo C++ IDE. After install Turbo C++, open it and create a C or C++ file with .c or .cpp extension. Then, include the graphics.h header file in your program for use fillellipse() function. Next, using the initgraph() function you have to initialize the graphics mode.

Now you can use fillellipse() function in your program. Now copy my code and paste in your C or C++ file in the Turbo C++ IDE. Do you know how to use graphics.h in turbo C++, if no just follow my link.

Drawing a filled ellipse with the default color by C or C++ programing language :

In this program, I show you how draw a filled ellipse using fillellipse() function with default color by C or C++ programing language. At first, you have to include require header file like graphics.h and conio.h at the beginning of the program. Then, using initgraph() function initializes the graphics mode.

Now, by the fillellipse() function draw a filled ellipse with the center at (300, 240), horizontal radius 140 and vertical radius 90. The ellipse will be filled with the default (current) drawing color. After drawing the filled ellipse, you have to use getch() function to wait for a key press by the user. Lastly, closing the graphics mode with closegraph() function.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
int main(void)
{
    int graphic_driver = DETECT, graphic_mode;
    initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
    fillellipse(300, 240, 140, 90);
    getch();
    closegraph();
    return 0;
}

Output :

After executing the compiled program, you should see the following filled ellipse with white color displayed on the screen by C or C++ programing language.

filled ellipse using fillellipse() function with default color by C or C++ programing language

Drawing filled ellipse with different color by C or C++ programing language :

In this program, I show you how draw a filled ellipse using fillellipse() function with different color by C or C++ programing language. At first, you have to include require library such as graphics.h and conio.h at the beginning of the program. Then, initialize the graphics mode using initgraph() function.

Next, setfillstyle() function use for set or change the fill color before drawing the filled ellipse using fillellipse() function. After drawing the filled ellipse, you have to use getch() function for enter any key press by the user. At last, close the graphics mode using closegraph() function. In this program, I call setfillstyle() function four times to draw four filled ellipse with different color before each fillellipse() function.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
int main(void)
{
    int graphic_driver = DETECT, graphic_mode;
    initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
    setfillstyle(1, 1);
    fillellipse(200, 150, 100, 50);
    setfillstyle(1, 2);
    fillellipse(450, 150, 100, 50);
    setfillstyle(1, 4);
    fillellipse(200, 300, 100, 50);
    setfillstyle(1, 5);
    fillellipse(450, 300, 100, 50);
    getch();
    closegraph();
    return 0;
}

Output :

After running the program, you should see the following filled ellipse with different color displayed on the screen by C or C++ programing language.

filled ellipse using fillellipse() function with different color by C or C++ programing language

Drawing filled ellipse with different fill style or pattern by C or C++ programing language :

In this program, I show you how draw a filled ellipse using fillellipse() function with different fill style or pattern by C or C++ programing language. At first, you have to include require library such as graphics.h and conio.h at the beginning of the program.

After initializing the graphics mode using initgraph() function, using setfillstyle() function change the fill style or pattern of the filled ellipse. Then, using getch() function take input any key by the user before close the graphics mode using closegraph() function. In this program, I call setfillstyle() function four times to draw four filled ellipse with different fill style or pattern before each fillellipse() function.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
int main(void)
{
    int graphic_driver = DETECT, graphic_mode;
    initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
    setfillstyle(8, 4);
    fillellipse(200, 150, 100, 50);
    setfillstyle(2, 4);
    fillellipse(450, 150, 100, 50);
    setfillstyle(7, 4);
    fillellipse(200, 300, 100, 50);
    setfillstyle(4, 4);
    fillellipse(450, 300, 100, 50);
    getch();
    closegraph();
    return 0;
}

Output :

After running the program, you should see the following image as output where filled ellipse with different fill style or pattern displayed on the screen by C or C++ programing language.

filled ellipse using fillellipse() function with different fill style or pattern by C or C++ programing language

Create animation with filled ellipse by C or C++ programing language :

In this program, I show you how you create animation with filled ellipse using fillellipse() function by C or C++ programing language. To create an animation using the fillellipse() function, you can use a loop that updates the position or color of the filled ellipse every time. In this program, I use the fillellipse() function to create a filled ellipse moves across the screen by updating the graphics mode.

At first, you have to include require library such as graphics.h, conio.h and dos.h at the beginning of the program. Now initialize the graphics mode using initgraph() function. Next, by setbkcolor() function set the background color red. Then in the while loop change the position of filled ellipse and using setfillstyle() function change the fill color of the filled ellipse. Here, I use kbhit() function to check any key press or not.

In the while loop use cleardevice() function for clear the screen before drawing the next filled ellipse. Then, use delay() function to control the animation speed. To get the maximum value of x and y coordinates of the graphics mode, you can use getmaxx() and getmaxy() functions. After that, using getch() function take input any key by the user before close the graphics mode using closegraph() function.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
    int graphic_driver = DETECT, graphic_mode;
    int x = 250, y = 250;
    int x_radius = 50, y_radius = 30;
    int i = 4, j = 4, k = 0;
    initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
    setbkcolor(4);
    while (!kbhit())
    {
        cleardevice();
        setfillstyle(1, k);
        fillellipse(x, y, x_radius, y_radius);
        x += i;
        y += j;
        k++;
        if (k == 16)
        {
            k = 0;
        }
        if (x + 50 >= getmaxx() || x - 50 <= 0)
        {
            i = -i;
        }
        if (y + 30 >= getmaxy() || y - 30 <= 0)
        {
            j = -j;
        }
        delay(20);
    }
    getch();
    closegraph();
    return 0;
}

Output :

When you run the program on your pc, you can see the following output of creating animation with filled ellipse by C or C++ programing language.

animation with filled ellipse using fillellipse() function by C or C++ programing language

Conclusion :

The fillellipse() function of graphics.h library is a useful tool for drawing filled ellipses in graphics mode. The function can be used to create various graphical elements and animations. In the above program, I show you how you create different type of filled ellipse with color and pattern. I also show you create a filled ellipse moves across the screen by C or C++ programing language. Thank you for visiting my site.

Scroll to Top