2. If we want to start graphics
programming then we need two files
which are GRAPHICS.H and
GRAPHICS.LIB. The graphic mode
functions require a graphics monitor
and adapter card such as Color
Graphics Adapter(CGA), Enhanced
Graphics Adapter(EGA) and Video
Graphics Array(VGA).
GRAPHIC MODEGRAPHIC MODE
Exit
Program
Exp
Explanation
Introduction
Exe file
3. Traditional XY coordinate system
Graphics XY coordinate system
XY Coordinate systemXY Coordinate system
Exit
Program
Exp
Explanation
Introduction
Exe file
4. Traditional XY Coordinate systemTraditional XY Coordinate system
Coordinate system
simply means that
how to pinpoint
any location on the
screen as an XY
value
We all should be
well known of
traditional XY
coordinate system,
which is commonly
used in math.
X-axis
Y-axis
(0,0)
Exit
Program
Exp
Explanation
Introduction
Exe file
5. Graphics XY Coordinate systemGraphics XY Coordinate system
Graphics coordinate systems typically
spell out the origin of the system.
The graphics coordinate system has an
origin that is located in the upper-left
corner of the window, with +ve X values
increasing to the right and +ve Y values
increasing down. X-axis
Y-axis
(0,0)
Exit
Program
Exp
Explanation
Introduction
Exe file
6. In computer the graphics XY
coordinate system is similar to
math coordinate system except it
applies to the client area of
windows.
Client area is the area, which
doesn't include the title bar,
scrollbars, and so on.
All values in the Graphics
coordinate system are positive
integers.
Exit
Program
Exp
Explanation
Introduction
Exe file
8. rectangle (left,top,right,bottom) :
This function draws a rectangle with
(left,top) as upper left of the rectangle &
(right,bottom) as its lower right of the
corner.
Exit
Program
Exp
Explanation
Introduction
Exe file
9. Circle( ):
Circle function takes X and Y
values with respect to top left
corner of the screen and third co-
ordinate is nothing but radius of
circle..
Exit
Program
Exp
Explanation
Introduction
Exe file
10. Closegraph( ) : The closegraph()
swithces back the screen from grpahics
mode to text mode. If you don’t use this
function then you may have undesirable
effects.Here this function is called after
the getch() function as screen shouldn’t
switch to text mode till user hits any key.
getch( ) : getch( ) function gets a
character from console but does not
echo it on screen.This is used to pause
the screen till user hits any key.
Exit
Program
Exp
Explanation
Introduction
Exe file
13. HEADER
“Headers" are libraries of code you may
insert in your program by including
them by reference in the top block.
Exit
Program
Exp
Explanation
Introduction
Exe file
14. #include<iostream.h>
Declares objects that control reading and
writing to the standard streams. This is
often the only header you need to include
to perform input and output from a C++
program.
cerr
cin
cout
wcerr
wcin
wcout
Exit
Program
Exp
Explanation
Introduction
Exe file
15. #include<conio.h>
Function Description
kbhit Determines if a keyboard key was pressed.
ungetch Puts a character back into the keyboard buffer.
putch Writes a character directly to the console.
cgets Gets a string directly from the console.
cprintf Formats and prints a string directly to the
console.
cputs Outputs a string directly to the console.
cscanf Reads and formats values directly from the
console.
Exit
Program
Exp
Explanation
Introduction
Exe file
16. #include<stdlib.h>
The name "stdlib" stands for
standard library.
stdlib.h includes functions involving
memory allocation, process control,
conversions and others.
Exit
Program
Exp
Explanation
Introduction
Exe file
17. #include<graphics.h>
This file contains definitions and
explanation of all the graphic functions
and constants.
Here we are dealing with graphic mode
function. To switch from text mode to
graphic mode, we have function called as
” initgraph ” .
Exit
Program
Exp
Explanation
Introduction
Exe file
18. Variables: x, y, xv, yv, r
Constructor: cirl();
Functions: Move(); cc();
cdx(); cdy();
Class of circleClass of circle
Exit
Program
Exp
Explanation
Introduction
Exe file
21. Color palettes
The graphics.h has declaration about
16 colors.In order to use the color in
your program you have to use the
functions like setcolor( ) ,setbkcolor( )
& setfillstyle( ).The function setcolor( )
sets the value of current drawing color
to color
setfillstyle( ) sets the current fill pattern
and fill color
setbkcolor( ) sets the value for
background color,which is by default
black
Exit
Program
Exp
Explanation
Introduction
Exe file
22. Color ValueBlack 0
Blue 1
GREEN 2
Cyan 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
Exit
Program
Exp
Explanation
Introduction
Exe file
24. EXPLANATION
IF THE COLOR VALUE IS EQUAL TO 15
WHICH IS THE LAST COLOR VALUE THEN
WE SHOULD SET COLOR VALUE “1”
HERE IN PROGRAM IS COL=0; IT MEANS
THAT ,HERE COLOR BECOME BLACK
WHICH WOULD BE INVISIBLE SO WE
SHOULD INCREASE COLOR BY
ONE,THAT SHOULD BE VISIBLE
Exit
Program
Exp
Explanation
Introduction
Exe file
25. Functions to move balls
void move(void)
{
setcolor(0);
circle(x,y,r);
x=x+xv;
y=y+yv;
setcolor(col);
circle(x,y,r);
} 0 for BLACK
Exit
Program
Exp
Explanation
Introduction
Exe file
26. Making 8 circles in main
circl p[8];
p[0].xv=1; p[0].yv=0;
p[1].xv=-1; p[1].yv=0;
p[2].xv=0; p[2].yv=-1;
p[3].xv=0; p[3].yv=1;
X(320)
Y(240)
If monitor has a
resolution of 640*480.
x=x+xv;
y=y+yv;
Exit
Program
Exp
Explanation
Introduction
Exe file
28. Function for changing the direction of a ballFunction for changing the direction of a ball
((x-axis))
inline void cdx(void)
{
xv=xv*-1;
cc();
}
X(320)
Y(240)
Exit
Program
Exp
Explanation
Introduction
Exe file
29. inline void cdy(void)
{
yv=yv*-1;
cc();
}
Function for changing the direction of a ballFunction for changing the direction of a ball
((y-axis))
X(320)
Y(240)Exit
Program
Exp
Explanation
Introduction
Exe file
30. Eight object of circles
MainMain
Exit
Program
Exp
Explanation
Introduction
Exe file
32. initgraph(&driver,&mode);
This function selects the best
resolution and direct that value to
variable mode
The two int variables driver,
mode are graphic driver and
graphic mode respectively.
The mode handles value that
tells us which resolution and
monitor we are using
The driver specifies the graphic
driver to be used. Three types of
drivers are CGA, VGA, EGA
Exit
Program
Exp
Explanation
Introduction
Exe file
35. setcolor(5);
Definition:
setcolor sets the current drawing
color
Declaration:
void setcolor(int color);
Remarks:
setcolor sets the current drawing
color to color
Exit
Program
Exp
Explanation
Introduction
Exe file
38. EXPLANATION
If our circle exceed from the left side
and behind the right side of rectangle
also below from the top and above
from the bottom, means the circle is
inside the rectangle then we will move
the function by calling (“move()”)
function.
Exit
Program
Exp
Explanation
Introduction
Exe file
39. If our circle is exceed from the right
side or behind the left side, then we
have to change the x-direction of
circle.
If our circle is above the top or below
the bottom of the rectangle then we
have to change the y-direction of
circle.
Exit
Program
Exp
Explanation
Introduction
Exe file
41. closegraph();
Definition:
Shuts down the graphics system
Declaration:
void closegraph(void);
Remarks:
closegraph deallocates all memory
allocated by the graphics system.
Exit
Program
Exp
Explanation
Introduction
Exe file
42. cleardevice();
Definition:
Clears the graphics screen
Declaration:
void cleardevice(void);
Remarks:
cleardevice erases the entire
graphics screen and moves the CP
(current position) to home (0,0).
Exit
Program
Exp
Explanation
Introduction
Exe file