“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
Graphics in C++
1.
2. Group Name
Pure ones
Presenters
Ali Murtaza 11014119-044
M. Hamid 11014119-007
QasimAli 11014119-128
M. Tayyab Chema 11014119-045
Ahsan Raza 11014119-017
3. Turbo C has a good collection of graphics libraries.
If you know the basics of C, you can easily learn
graphics programming.
Why we use graphics ?
We use graphics in C language to give a different
look to our program.
Function related graphics are use to create different
shapes in different colour.
4. Files for compiler to work in graphics.
The header file “graphics.h” i.e built-in function is
use in graphics.
These files stores in Borland graphics interface (BGI)
files. These files contain graphics drive program.
Display modes in C .
The output of a program can be displayed on the
screen in two modes.
Text mode.
Graphics mode.
5. In text mode screen is normally divided into rows
and columns. We can move the cursor to specified
location by using “gotoxy (x,y);” function.
In text mode there are 80 columns (0-79) and 25
rows (0-24).
In text mode only text can be displayed.
6. In graphics mode the screen is divided into small
dots called pixels.
For example:
In VGA monitor the screen is divided into 480
rows and 640 columns of dots. Thus the monitor
VGA screen is divided into 640 X 480 pixels.
The resolution of different type of (display adopter)
are
VGA 640 X 480
SVGA 800 X 600
7. The computer display system must be initialized into
graphics mode before calling the graphics function.
Function for initialization of graphics:
The “initgraph” function is used to initialized the
graphics mode.
This function is already defined in “graphics.h”
header file.
8. Syntax
The syntax of initgraph is:
initgraph(&driver, &mode,”path”);
Driver
Represents the graphics driver installed in computer. It
may be an integer variable or an integer constant.
Mode
Represents the output resolution on the computer screen.
The normal mode for VGA is VGAHI. It gives the highest
resolution.
9. &
Represents the addresses of constants for driver and
mode.
Path
Represents the path of VGA driver.
Which “ C:compiler nameBGI”.
10. There are two method of using initgraph function.
Manually
In this way you have to tell the computer all about drivers or
modes of VGA. In this way you don’t have to use & operator.
For example: initgraph(vga,vgahi,”C:compiler nameBGI ”).
Auto-detect
In this method you have only declare two integer type variables
name as you wish. Initialize the 1st variable with a key word
“DETECT”. In this method we should use & operator.
For example: initgraph(&driver, &mode,”C:compiler nameBGI”);
11. The cleardevice function is used to clear screen in
graphics mode as clrscr( ) function is used in text
mode.
Syntax cleardevice( );
Closegraph function
The closegraph function is used to restore ( turn of all the
graphics ) the screen into text mode.
Syntax closegraph();
12. The outtext function is used to print text on the screen
in graphics mode.
Syntax outtext(Any sentence or character);
Moveto function
The moveto function is used to move the cursor on the screen
in specific location.
Syntax moveto(x , y);
X represents the x-coordinate of the screen.
Y represents the y-coordinate of the screen.
13. #include<conio.h>
#include<graphics.h>
void main()
{
cleardevice();
int d,m;
d= DETECT;
initgraph( &d, &g, “C:TCBGI”);
outtext(I love programming);
moveto (250,179);
outtext(I love programming);
getch();
closegraph();
}
14. The outtextxy function is similar to the outtext function but it is
used to print text on the specified location. This function is both to
outtext and moveto function.
Syntax outtextxy(x,y,”any string or character”);
Settextstyle function
The settextstyle function is used to define text style in graphics
mode.
Syntax settextstyle(style, direction, size);
Style represents the font style and its value is 0-10.
Direction represents the direction of text (horizontal or vertical) its
value is 0-1.
Size represents the font size of the text its value is 0-72.
15. The setcolor function is used to define the color of the
object or text in graphics mode.
Syntax setcolor(color );
There are 16 color in declared in graphics.h .
BLACK: 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
16. The setbkcolor function is used to define back ground
color on the output screen.
Syntax setbkcolor(color);
18. The circle function is used to display the circle on the
out put screen.
Syntax circle( x, y, radius );
Arc function
The arc function is used to draw a circular arc starting from a
specified angle from to another specified angle.
Syntax arc ( x, y, starting angle, ending angle, radius);
Where all parameters are both circle and arc have integer type.
19. The line function is used to draw a line between two points on
the screen.
Syntax line (x1,y1,x2,y2);
Rectangle function
The rectangle function is used to draw a rectangle between
two points on the screen.
Syntax rectangle (x1,y1,x2,y2);
Where x1, y1 specify the x ,y coordinate of the first point. And
x2 , y2 specify the x , y coordinate of the second point. All
four parameters are integer type.