Find the mid-point of your screen in c graphics


Find the mid-point of your screen in c graphics

The mid point of the screen is find with the help of getmaxx() and getmaxy() functions.

getmaxx() :

It returns the maximum x value for the current graphics and driver. That is, it returns the maximum x screen coordinate.

getmaxy() :

It returns the maximum y value for the current graphics and driver. That is, it returns the maximum y screen coordinate.


Now if you divide these functions with 2 you can get the mid point of the screen.

getmaxx()/2----horizontal mid point.
getmaxy()/2---vertical mid point.

Take two int variables :

int midx,midy;

Now assign the following values to these variables like:

midx=getmaxx()/2;
midy=getmaxy()/2;

That is (midx,midy) gives yoy the mid-point of your screen.

Example :

To draw circle at the center of your screen :

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

void main()
{
int d,m;
int midx,midy;

d=DETECT;
initgraph(&d,&m,"c:\\tc\\bgi");

midx=getmaxx()/2;
midy=getmaxy()/2;

setfillstyle(6,2);
circle(midx,midy,50);
floodfill(midx,midy,15);

getch();
closegraph();
}

Output :