Computer Graphics, Attributes of Graphics , C Language Assignment Help

Assignment Help: >> Introduction to C language >> Computer Graphics, Attributes of Graphics , C Language

Introduction to  Computer Graphics 

Computer graphics remains one of the most exciting and rapidly growing computer fields. Today, we find computer graphics used routinely in such diverse areas as science, engineering, medicine, business, industry, government, art, entertainment, advertising, education, and training. Computer graphics methods are now commonly used in making motion pictures, music videos, and television shows. Sometimes the graphics scenes are displayed by themselves, and sometimes graphics objects are combined with the actors and live scenes. 

Attributes of Graphics 

initgraph: This function initializes the graphics system. Prototype is defined in "graphics.h". The syntax is given below:

void far initgraph (int far *gd, int far *gm, char far *pathtodriver);

Where, gd is graphics driver and gm is graph mode. In real application to detect graphics drives DETECT macro is used.

closegraph: This function shuts down the graphics system. The declaration is given below. Prototype is defined "graphics.h".

void far closegraph (void);

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

void far restorecrtmode(void);

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

int far graphresult(void);

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

 

getmaxx() and getmaxy(): The getmaxx() returns maximum x screen coordinate and getmaxy() returns maximum y screen coordinate. Its prototype is defined in "graphics.h". These functions can be declared as under.

int far getmaxx(void);

int far getmaxy(void);

 

circle: This function draws a circle(x, y) of the given radius. This function is declared as under.

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

 

Arc: This function draws an arc. This function is declared as,

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

Where (x, y) is the center point. The variable sa and ea are the start and end angles in degrees and variable r is the radius.

Syntax: void arc(int x, int y, int startangle, int endangle, int rad);

 

Ellipse: This function draws an elliptical arc. This function is declared as,

void far ellipses (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 start and end angles in degrees. The variable xr and yr are horizontal and vertical radii.

 

line: Draws a line between two specified points. This function is declared as,

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

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

 

bar: This function draws a bar using given co-ordinates. This function can be declared as,

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

Draws the two dimensional bar.

Note: This function draws a filled-in, rectangular, two dimensional bar. The bar is filled using the current fill pattern and fill color. bar() does not outline the bar. To draw an outlined two-dimensional bar, use bar3d() with depth equal to 0.

 

bar3d(): This function is used for drawing a 3-D bar.

Syntax: void bar3d(int left, int top, int right, int bottom, int depth, int flag);

Note: bar3d () draws a three-dimensional rectangular bar, and then fills it in using the current fill pattern and fill color. The three-dimensional outline of the bar is drawn in the current line style and color. The bar's depth, in pixels, is given by depth. To calculate typical depth for bar3d (), take 25%of the width of the bar. The flag parameter governs whether a three-dimensional top is put on the bar. If flag is nonzero, a top is put on; otherwise, no top is put on the bar (making it possible to stack several bars on top of one another).

 

setcolor(): This function sets the current drawing color. This is declared as,

void far setcolor (int color);

 

outtextxy: Displays a string to the specified location (graphics mode). This function is declared as given under.

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

 

settextstyle: This function sets the current text attributes. This function is declared as,

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

 

settextjustify: This function sets text justification for graphics mode. This function is declared as per given below:

void far settextjustify(int horizantal, int vertical);

 

drawploy: This function is used to draw the outline of a polygon.

Syntax: void drawpoly(int num, int *polypoints);

Note: drawpoly() draws a polygon with num points, using the current line style and color. Poly points points to a sequence of (num *2) integers. Each pair of integers gives the x and y coordinates of a point on the polygon.

 

getbkcolor: This function returns the current background color.

Syntax: int getbkcolor();

 

getgraphmode: This function is used to returns the current graphics mode set by initgraph() or setgraphmode().

Syntax: int getfraphmode();

Note: The enumeration graphics_mode, defined in graphics.h, gives names for the predefined graphics modes.

 

getimage: This function saves a bit image of the specified region into memory.

Syntax: void getimage (int left, int top, int right, int bottom, void *bitmap);

Note: getimage() copies an image from the screen to memory, left, top, right, and bottom define the area of the screen from which the rectangle is to be copied. Bitmap points to the area in memory where the bit image is stored.

 

getmaxcolor: This function returns maximum color value for the current graphics driver and mode that can be passed to the setcolor() function.

Syntax: int getmaxcolor( );

 

getmodename: This function is used to obtain the name of a specified graphics mode.

Syntax: char* getmodename(int mode_number);

Comments: getmodename() accepts a graphics mode number as input and returns a string containing the name of the corresponding graphics mode. The return values are useful for building menus or displaying status.

Returns: A pointer to a string with the name of the graphics mode.

 

getpixel: This function gets the color of a specified pixel.

Syntax: unsigned getpixel(int x, int y);

 

gettextsettings: This function gets information about the current graphics text font.

Syntax: void gettextsettings(struct textsettingstype *info);

Note: gettextsettings() fills the textsettingstype structure pointed to by info with information about the current text font, direction, size, and justification. The textsettingstype structure is defined in graphics.h as follows:

                struct textsettingstype

                {

                                int font;

                                int direction;

                                int charsize;

                                int horiz;

                                int vert;

                };

 

setbkcolor: This function is used to sets the current background color using the palette.

Syntax: void setbkcolor(int color);

Note: The color parameter can take a value from 0 to 15. If you use an EGA or a VGA and you change the palette colors using setpalette() or setallpalette(), the color value you use might not give you the correct color. This is because the parameter to setbkcolor() indicates the entry number in the current palette rather than a specific color.

 

setallpalette: This function changes all palette colors as specified.

Syntax: void setallpalette (struct palettetype *palette);

 

textheight: This function returns the height of a string in pixels.

Syntax: int textheight(char *textstring);

Comments: This function is useful for adjusting the spacing between lines, sizing a title to make it fit on a graph or in a box etc.

 

textwidth: This function returns the width of a string in pixels.

Syntax: int textwidth(char *textstring);

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd