0% found this document useful (0 votes)
3K views10 pages

INITGRAPH : This Function Is Used To Initialize: Graphics

This document discusses graphics functions in C programming. It explains functions like initgraph() to initialize graphics mode, closegraph() to close graphics mode and return to text mode. Other functions described include setcolor() to set drawing color, line() to draw lines, circle() to draw circles, rectangle() to draw rectangles, putpixel() to put pixels, outtext() to display text.

Uploaded by

Yogesh Katre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views10 pages

INITGRAPH : This Function Is Used To Initialize: Graphics

This document discusses graphics functions in C programming. It explains functions like initgraph() to initialize graphics mode, closegraph() to close graphics mode and return to text mode. Other functions described include setcolor() to set drawing color, line() to draw lines, circle() to draw circles, rectangle() to draw rectangles, putpixel() to put pixels, outtext() to display text.

Uploaded by

Yogesh Katre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

GRAPHICS

Now,to switch text mode to graphics modewe use a


function initigraph() and to return from graphics mode
to text mode another function used closegraph() is
used.All this function present in graphics.h header file.

INITGRAPH( ): This function is used to initialize


with the graphics library and changes to the graphics
screen. The general syntax of this function is:
initgraph(graphics_driver,graphics_mode,driv
er_path);
Example:
int gd,gm;
gd=DETECT;
initgraph(&gd,&gm,”C://Turboc2//BGI);
This is used to initialize the graphics mode with
automatic detection and seting in the possible resolution
of the monitor screen.
closegraph ( ): This function is used to terminate the
graphics mode which is the set by the initgraph( )
function.It stores the originalvideo mode.

Graphics Function:
textmode( ): It is used to set the numbers of rows and
columns screen.It has the following form,
textmode(c40);
textbackground( ) : It is used to set the background
color in the text mode.It has following form.
Testbackground(n);
Symbol Color Symbol Color
Value value
BLACK 0 DARKGRAY 8
BLUE 1 LIGHTBLUE 9
GREEN 2 LIGHTGREEN 10
CYAN 3 LIGHTCYAN 11
RED 4 LIGHTRED 12
MAGNENTA 5 LIGHTMAGENTA 13
BROWN 6 YELLOW 14
LIGHTGRAY 7 WHITE 15
NOTE THAT THE SYMBOL CAN ALSO BE USED
IN THE FUNCTION INSTEAD OF COLOR VALUE.
textcolor( ): This function is used to set the color for the text going
to be displayed. It has the following form.
textcolor( n);
NOTE THE COLOR VALUE ABOVE ALSO APPLICABLE FOR
THE TEXT COLOR.
gotoxy( ) function:
cputs( ) function:
This function is used to display a text message in the monitor screen
in the graphics mode.It has the following form.
cputs(“text message);
Example 1.

restorecrtmode( ) function:
This function is also used to terminate the graphics mode and restore
the original video mode.getgraphmode( ) and setgraphmode( )
function can be used with this function.which is used to switch
between graphics mode and original video mode.
Setcolor( ) function:
This function is used to specify the color for a graphical picture going
to be displayed.It has the following form:
Setcolor(m);
Or setcolor(RED);
Setbkcolor( ) function:This function is used to set the background
color for the monitor screen. It has the following form
setbkcolor(1); OR setbkcolor(BLUE)
putpixel( ) function:
This function is used to draw a point on the monitor
screen in the given co-ordinates position. It has the
following form.
putpixel(x,y,n);
where x and y are integers representing the coordinates
to draw the point.
n is an integers referring the color code or symbol of the
pixel or point.
Example:
putpixel(100,150,4);
putpixel(100,150,RED);
putpixel(100,150);
Note the color code or symbol of the pixel is optional..

line( ) function:
This function is used to draw a line on the monitor
screen in the given coordinates position. It has the
following form.
line(x1,y1,x2,y2);
moveto( ) function:
This function is used to move the control from the
current position to the specified coordinates .It has the
following form.
moveto(x,y);
where x and y are integers representing the new
coordinates position.
Example:
moveto(200.300);

lineto( ) function:
This function is used to draw a line from the current
position to a specific coordinates. It has the following
form.
lineto(x,y);
where x and y are integers representing the ending point
of the line.
Example:
moveto( 100,80);
lineto(100,250);

programes on graphics.
outtext( ) function:
This function is used to display a text message in the
graphics mode at the current position.It has the
following form.
outtext(“text message”);

Example 2,3 explain......

cleardevice( ) function:
This function is used to clear the screen in graphics
mode.It has the following forms.
cleardevice( );

rectangle( ) function:
This function is used to draw a rectangle by specific the
diagonal coordinates.It has the following form.
rectangle(x1,y1,x2,y2);
Example: rectangle(100,80,300,200)

setlinestyle( ) function:
This function is used to set a new line style .It has the
following form.
setlinestyle(m,n,t);
where m is an integer or symbol representing the line
style.
Where n is an unsigned integer representing the user
defined pattern.It is neglected when the line style is
other than USERBIT_LINE.
Where t is an integer or symbol representing the
thickness of the line.
Symbol Integer Value Meaning
SOLID_LINE 0

DOTTED_LINE 1 ...........................

CENTER_LINE 2 --------------------

DASHED_LINE 3 - ---- ---


USERBIT_LINE 4 User define line
style

setfillstyle( ) function:
This function is used to fill a closed boundary by a
pattern .It has the following form.
setfillstyle(m,c);
where m is an integer or symbol representing the
pattern.
Where c is also an integer or symbol representing the
color.
Symbol Integer Value Meaning
Empty_FILL 0 Background color
SOLID_FILL 1 Solid Color
LINE_FILL 2 Horizontal Line
LTSLASH_FILL 3 //////Patern
SLASH_FILL 4 THICK /////Patern
BKSLASH_FIL 5 THICK \\\\\\\ Patern
L

floodfill( ) function:
This function is used to fill an area with any required
style.Note that the area should have closed boundary
lines.It has the following form.
floodfill(m,n,c);
where m and n are integer representing the coordinates
which lie inside the boundary line.
Where c is an integer or symbol representing the border
color.
Example:
setcolor(RED);
setfillstyle(7,4);
rectangle(50,40,180,200);
floodfill(51,41,RED);
Explain example with graphics.
arc( ) function:
This function is used to draw a circular arc by specific
the center ,radius,and starting and ending angle.
arc(x,y,sa,ea,r)

Function Description
It initializes the graphics system by
initgraph loading the passed graphics driver then
changing the system into graphics mode.
It returns the maximum X coordinate in
getmaxx
current graphics mode and driver.
It returns the maximum X coordinate in
getmaxy
current graphics mode and driver.
setcolor It changes the current drawing colour.
Default colour is white. Each color is
Function Description
assigned a number, like BLACK is 0 and
RED is 4. Here we are using colour
constants defined inside graphics.h header
file.
It sets the current fill pattern and fill
setfillstyle
color.
It draws a circle with radius r and centre
circle
at (x, y).
It draws a straight line between two
line
points on screen.
It draws a circular arc from start angle till
arc
end angle.
It is used to fill a closed area with current
fill pattern and fill color. It takes any
floodfill
point inside closed area and color of the
boundary as input.
It clears the screen, and sets current
cleardevice
position to (0, 0).
It is used to suspend execution of a
delay
program for a M milliseconds.
It unloads the graphics drivers and sets
closegraph
the screen back to text mode.

You might also like