Graphics Mode Functions in C
To display any picture on a monitor, the graphics mode is set for resolution and colour. All graphics functions can be included in a program using #include<graphics.h>
Graphics Mode Functions:
initgraph() Function: It is used to set the graphics mode. It has the following form:
initgraph(graphic_driver, graphic_mode, driver_path);
closegraph() Function: It is used to terminate the graphics mode which is set by the initgraph() function. It restores the original video mode. It has the following form:
closegraph();
getmaxx() Function: This function is used to get the maximum value of x coordinate in the current resolution.
Example:
max=getmaxx();
getmaxy() Function: It is used to get the maximum value of the y coordinate in the current resolution.
Example:
xy=getmaxy();
restorecrtmode() Function: It is also used to terminate the graphics mode and restore the original video mode. It has the following form:
restorecrtmode();
setcolor() Function: It is used to specify the colour for a graphical picture going to be displayed. It has the following form:
setcolor(m);
where m is an integer or symbol representing the colour of the drawing.
setbkcolor() Function: This function is used to set the background colour for the monitor screen. It has the following form:
setbkcolor(m);
setpalatte() Function: It is used to set the background colour with the index.
Example:
setplatte(0, RED);
putpixel() Function: This function is used to draw a point on the monitor screen. It has the following form:
putpixel(x, y, n);
line() Function: It is used to draw a line on the monitor screen in the given coordinate position. It has the following form:
line(x1, y1, x2, y2);
moveto() Function: It is used to move the control from the current position to the specified coordinate. It has the following form:
moveto(x, y);
lineto() Function: This function is used to draw a line from the current position to a specific coordinate. It has the following form:
lineto(x, y);
linerel() Function: This function is used to draw a line from the current position to a point by specifying its distance relative to the current position. It has the following form:
linerel(dx, dy);
outtext() Function: This function is used to display a text message in graphics mode at the current position. It has the following form:
outtext("text message");
outtextxy() Function: This function is used to display a text message in a specific location on the monitor screen. It has the following form:
outtextxy(m, n, "text message");
where m specifies the position on the x-axis and n specifies the position on the y-axis.