0% found this document useful (0 votes)
36 views

Functions in C and Graphics

Functions in C and Graphics

Uploaded by

mukesh dhabe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Functions in C and Graphics

Functions in C and Graphics

Uploaded by

mukesh dhabe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Study of Graphics function in C

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); .

Graphics functions in c with syntax


<graphics.h> :-In the above program a ‘graphics.h’ the header file is included. This header file contains all prototype and the
definition of all graphics functions. Before starting any Drawing action we need to initialize graphics mode.

<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.

Declaration:- void circle(int x, int y, int radius);

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.

Declaration:- void setcolor(int color);


1. Study of Graphics function in C

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:-

Declaration:- void getarccoords(struct arccoordstype *var);

getbkcolor();-Function getbkcolor returns the current background-color.

Declaration:- int getbkcolor();

E.g. color = getbkcolor(); // color is an int variable


If current background color is GREEN, color will be 2, or you can also use color name in capital latter.

getcolor();- getcolor function returns the current drawing color.

Declaration :- int getcolor();

E.g. a = getcolor(); // a is an integer variable


if current drawing color is WHITE then a will be 15. Functions in C and Graphics

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.

Declaration:- int getmaxcolor();

getpixel();- getpixel function returns the color of pixel present at location(x, y).

Declaration:- int getpixel(int x, int y);

gety();-gety function returns the y coordinate of current position.

Declaration:- int gety();

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);

outtext();- outtext function displays text at current position.

Declaration:- void outtext(char *string);

outtextxy();-outtextxy function display text or string at a specified point(x,y) on the screen.

Declaration:- void outtextxy(int x, int y, char *string);


x, y are coordinates of the point and the third argument contains the address of the string to be displayed.

putpixel();-putpixel function plots a pixel at location (x, y) of the specified color.

Declaration:- void putpixel(int x, int y, int color);


1. Study of Graphics function in C

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.

Sector();- sector function draws and fills an elliptical pie slice.

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.

Declaration:- void setbkcolor(int color);

setfillstyle();- function sets the current fill pattern and fill color.

Declaration:- void setfillstyle( int pattern, int color);

setlinestyle:- This function is used to change the lining style.

Declaration of setlinestyle function:- void setlinestyle int linestyle, unsigned pattern, int thickness);

extheight():- This function returns the height of a string in pixels.

Declaration:- int textheight(char *string);

Textwidth();- This function returns the width of a string in pixels.

Declaration:- int textwidth(char *string);

You might also like