C Graphics in-built Functions


Some important C Graphics Function

Following are the important graphics functions present in graphics.h header file :

initgraph() :

It initializes the graphics system.

To start the graphics system, u must call this function.

Syntax :

initgraph(int far *graphdriver,int far *graphmode,char far pathtodriver);

This function initializes the graphics system by loading a graphics driver from disk then putting the system into graphics mode.

It also resets all graphics settings(color,current position) to their defaults.

Arguments used :

*graphdriver:

Integer that specifies the graphics driver to be used.

*graphmode :

Integer that specifies the initial graphics mode.
If graphmode==DETECT then initgraph sets *graphmode to the
highest resolution available for the detected driver.

pathtodriver :

Specifies the directory path where initgraph looks for graphics driver(*.BGI) first.

circle() :

This function is used to draw the circle.

Syntax :

circle(int x,int y,radius);

Argument :

(x,y)---Centre point of circle.

radius--radius of the circle.

rectangle() :


This function is used to draw rectangle. It draws the rectangle in the current line style, thickness and drawing color.

Syntax :

rectangle(int left,int top,int right,int bottom);

(left,top) is the upper left corner of the rectangle and (right,bottom) is the bottom right corner of the rectangle.

bar() :

It is used to draw the bar. It draws filled-in,rectangular,two-dimensional bar.

Syntax :

bar(int left,int top,int right,int bottom);

bar3d() :

It draws a rectangular 3-d bar,then fills it with current fill pattern and fill color.

Syntax :

bar3d(int left,int top,int right,int bottom,int depth,int topflag);

depth--bar's depth in pixel.

topflag--goverens whether a three dimensional top is put on the bar.

arc() :

It draws a circular arc in the current drawing color.

Syntax :


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

(x,y)---centre point of arc
stangle---starting angle
endangle---ending angle

Note : If starting angle=0 and ending angle=360 then a circle is formed.

ellipse() :

It is used to draw elliptical arc in the current color.

Syntax :

ellipse(int x,int y,int stangle,int endangle,int xradius,int yradius);

xradius---Horizontal axis
yradius---Vertical axis

fillellipse() :


It draws an ellipse and fill it with current fill color and fill pattern.

Syntax :

ellipse(int x,int y,int stangle,int endangle,int xradius,int yradius);

line() :

It draws a line between two specific points.

Syntax :

line(int x1,int y1,int x2,int y2);

cleardevice() :

It clears the graphics screen. It erases all the graphics screen and moves the current position to
(0,0).

setcolor() :

It sets the current drawing color.

Syntax :

setcolor(int color);

getcolor() :

It returns the current drawing color.

Syntax :

getcolor(void);

settextstyle() :

It sets the current text characteristics. It sets the text font, the direction in which text is displayed and the size of the characters.

Syntax :

settextstyle(int font,int direction,int charsize);

direction values:-

if this argument is 0---Horizontal direction
if this argument is 1---Vertical direction

outtextxy() :

It displays a string at the specified position.

Syntax :

outtextxy()int x,int y,textstring);

floodfill() :

It fills a bounded region.

Syntax :

floodfill(int x,int y,int border);

Here (x,y) is the 'seed point'.

If the seed is within enclosed area, the inside will be filled.
If the seed is outside the enclosed area,the exterior will be filled.

Imp Note : The value of the border should be the value of MAX_COLOR that is 15.

setfillstyle() :

It sets the current fill pattern and fill color.

Syntax :

setfillstyle(int pattern,int color);

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.

closegraph() :

It shuts down the graphics system.

0 comments:

Post a Comment