Unit - 3.b PWC Graphics
Unit - 3.b PWC Graphics
Introduction:
int main()
{
int gd = DETECT, gm;
getch();
closegraph();
return 0;
}
To begin with we have declared two variables of int type gd and gm for graphics driver
and graphics mode respectively, you can choose any other variable name as well.
DETECT is a macro defined in "graphics.h" header file, then we have passed three
arguments to initgraph function first is the address of gd, second is the address of gm
and third is the path where your BGI files are present (you have to adjust this
accordingly where you Turbo C compiler is installed).
Initgraph function automatically decides an appropriate graphics driver and mode such
that maximum screen resolution is set, getch helps us to wait until a key is pressed,
closegraph function closes the graphics mode, and finally return statement returns a
value 0 to main indicating successful execution of the program. After you have
understood initgraph function then you can use functions to draw shapes such as circle,
line , rectangle, etc.
C graphics functions
1. arc- void arc(int x, int y, int stangle, int endangle, int radius);
2. bar - void bar(int left, int top, int right, int bottom);
3. bar3d - void bar3d(int left, int top, int right, int bottom, int depth, int topflag);
8. ellipse - void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);
17. line - void line(int x1, int y1, int x2, int y2);
21. rectangle - void rectangle(int left, int top, int right, int bottom);
24. setlinestyle - void setlinestyle( int linestyle, unsigned upattern, int thickness );
https://www.programmingsimplified.com/c/graphics.h#functions
16GET26 – C Programming – I CSE A – 2018 Batch - C Graphics
Example programs:
void main()
int gd = DETECT,gm;
int x ,y ,radius=80;
x = getmaxx()/2;
y = getmaxy()/2;
circle(x, y, radius);
getch();
closegraph();
Output:
16GET26 – C Programming – I CSE A – 2018 Batch - C Graphics
void main()
int gd = DETECT,gm;
getch();
closegraph();
Output:
16GET26 – C Programming – I CSE A – 2018 Batch - C Graphics
void main(){
int gd = DETECT,gm;
int x ,y;
x = getmaxx()/2;
y = getmaxy()/2;
getch();
closegraph();
Output:
16GET26 – C Programming – I CSE A – 2018 Batch - C Graphics
void main() {
x = getmaxx()/2;
y = getmaxy()/2;
setcolor(RED);
circle(x, y, 30);
setcolor(GREEN);
circle(x, y, 50);
setcolor(YELLOW);
circle(x, y, 70);
setcolor(BLUE);
circle(x, y, 90);
getch();
closegraph();
Output: