Loading....
Coupon Accepted Successfully!

 

Few Additional Graphics Functions

C++ supports enormous graphic functions. It is beyond the scope of this chapter to explain all the functions in a comprehensive manner. Nevertheless, an attempt is made to explain a few graphics functions. They are as follows:

(1) line();

This function draws a line between two specified points and is declared as below.

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

This function draws a line from (x1, y1) to (x2, y2) using the current color, line style, and thickness.

(2) circle();

This function draws a circle at (x, y) of the given radius and is declared as below.

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

(3) arc();

This function draws an arc and is declared as below.

void far arc (int x, int y, int sa, int ea, int r);

where (x, y) is the center point. The variables sa and ea are the starting and ending angles, respectively, in degrees, and the variable r is the radius.

(4) ellipse();

This function draws an elliptical arc and is declared as below.

void far ellipse (int x, int y, int sa, int ea, int xr, int yr);

where (x, y) is the center point. The variables sa and ea are the starting and ending angles in degrees, respectively. The variables xr and yr are horizontal and vertical radii, respectively.

(5) bar();

This function draws a bar using the given co-ordinates. The bar() function draws a filled-in, rectangular, two-dimensional bar. This function can be declared as below.

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

(6) rectangle();

The function rectangle() draws a rectangle. Its syntax is as follows:

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

(7) moveto();

The function moveto() moves the current position to view the port position (x, y).

Its syntax is as follows:

void far moveto(int x,int y);

(8) closegraph();

This function shuts down the graphics system. The declaration is as below. The prototype is defined in “graphics.h.”

void far closegraph (void);

(9) restorecrtmode();

This function restores the screen mode to its pre-initgraph setting. Its prototype is defined in “graphics.h.”

void far restorecrtmode (void);

(10) graphresult();

This function returns an error code for the last failed graphics operation and is defined as below.

int far graphresult(void);

It returns the error code for the last graphics execution that reported an error and resets the error level to grOK, where grOK is the enumerated error code.

(11) getmaxx(); and getmaxy();

The getmaxx() returns the maximum x screen coordinate, and getmaxy() returns the maximum y screen coordinate. Its prototype is defined in “graphics.h.” These functions can be declared as below.

int far getmaxx (void);

int far getmaxy (void);

(12) setcolor();

This function sets the current drawing color and is declared as below.

void far setcolor (int color);

(13) outtextxy();

This function displays a string at the specified location (graphics mode) and is declared below.

void far outtextxy (int x, int y, char far *textstring);

(14) settextstyle();

This function sets the current text attributes and is declared below.

void far settextstyle(int font, int direction, int fontsize);

This functions has three integer arguments. The first argument indicates font; the second, direction; and the third, size of the font.

(15) settextjustify();

This function sets the text justification for the graphics mode and is declared as below.

void far settextjustify(int horiz, int vert);

It affects the text output with outtext() function, and so on. The text is justified horizontally and vertically.

(16) getcolor();

This function returns the current drawing color and is declared as follows:

void far getcolor(void);





Test Your Skills Now!
Take a Quiz now
Reviewer Name