Functions in C and Graphics
Functions in C and Graphics
<stdio.h> :-file ‘stdio.h’ stands for Standard input-output, it is to be included at the beginning of the every C Program. (Functions in C
and Graphics )
<conio.h> :- This header file ‘conio.h’ stands for Console input-output, it uses somewhere in the program when the program doesn’t
scanf(); :- It is used for taking input in C.
printf(); :- This function is use for print the output on screen give proper output. it is also return type which work with function ‘getch();’
Circle(); :- This function Draw a circle at (x,y) of the given radius. This function is declared as under.void far circle(int x,
int y, int radius); ‘or’circle(getmaxx, getmaxy, radius); .
<dos.h>:- This DOS Disc Operating system, it is also a header file in C program for DOS type screen.
initgraph(); :- This function initialize the graphics system. Prototype is defined in ‘graphics.h’. It is declared as per given below.
getmaxx(); :- This function return maximum X coordinate on the screen. Its Prototype is defined in ‘graphics.h’ . And declared as
under.int far getmaxx (void);
getmaxy(); :- This function return maximum Y coordinate on the screen. Its Prototype is defined in ‘graphics.h’ . And declared as
under.int far getmaxy (void);
setcolor(); :- This function sets the current drawing color . This is declared as under.void for set color (int color);
closegraph(); :-This function shuts down the graphics system. The declaration is as under. Prototype is defined in ‘graphics.h’.void
far closegraph(void); ‘or’ closegraph();
arc:- “arc” function is used to draw an arc with center (x, y) and 1st angle specifies the starting angle, end angle specifies the end angle
and the last parameter specifies the radius of the arc. arc function can also be used to draw a circle but for that starting angle and end
angle should be 0 and 360 respectively.
Declaration:- void arc(int x, int y, int 1stangle, int endangle, int radius);
Circle:- circle function is used to draw a circle with center (x,y) and the third parameter specifies the radius of the circle.
setcolor( ):-In Turbo C Graphics each color is assigned a number. A total of 16 colors are available. The number of available colors
depend on the current graphics mode and driver.
For Example- BLACK is assigned 0, and BLUE is assigned 9 ( Instead of color value, you can put their name in capital Latter) etc.
setcolor function is used to change the current drawing color.
For Example- setcolor(BLUE) or setcolor(9) changes the current drawing color to RED. Remember that the default drawing color is
WHITE.
ellipse :- Ellipse is used to draw an ellipse (x,y) are coordinates of the center of the ellipse, stangle is the starting angle, end angle is
the ending angle, and the fifth and sixth parameters specify the X and Y radius of the ellipse. To draw a complete ellipse strangles and
end angle should be 0 and 360 respectively.
Declaration:- void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);
getarccoords:-getarccoords function is used to get coordinates of arc which is drawn most recently. arccoordstype is a predefined
structure which is defined as follows:-
getimage();-getimage function saves a bit image of a specified region into memory, the region can be any rectangle. getimage copies
an image from 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.
Declaration:- void getimage(int left, int top, int right, int bottom, void *bitmap);
getmaxcolor();- function returns maximum color value for current graphics mode and driver. Total number of colors available for
current graphics mode and driver are ( getmaxcolor() + 1 ) as color numbering starts from zero.
getpixel();- getpixel function returns the color of pixel present at location(x, y).
line();- line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and (x2,y2) are end points of the line.The code
given below draws a line.
Declaration:- void line(int x1, int y1, int x2, int y2);
For example, if we want to draw a GREEN color pixel at (35, 45) then we will write putpixel(35, 35, GREEN); in our c program, putpixel
function can be used to draw circles, lines, and ellipses using various algorithms.
Declaration:- void sector( int x, int y, int stangle, int endangle, int xradius, int yradius);
setbkcolor();- setbkcolor function changes current background color e.g. setbkcolor(YELLLOW) changes the current background color
to YELLOW.
Remember that default drawing color is WHITE and background color is BLACK.
setfillstyle();- function sets the current fill pattern and fill color.
Declaration of setlinestyle function:- void setlinestyle int linestyle, unsigned pattern, int thickness);