Documente Academic
Documente Profesional
Documente Cultură
(DCO-511)
Submitted by:
UMAIR RIAZ
Roll. No. 16-DCS-067
Diploma in Computer Engineering- V Semester
Program.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = EGA, gmode = EGAHI, errorcode;
int x, y, ht;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x = getmaxx() / 2;
y = getmaxy() / 2;
ht = textheight("W");
setactivepage(1);
line(0, 0, getmaxx(), getmaxy())
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, "This is page #1:");
outtextxy(x, y+ht, "Press any key to halt:");
setactivepage(0);
outtextxy(x, y, "This is page #0.");
outtextxy(x, y+ht, "Press any key to view page #1:");
getch();
setvisualpage(1);
getch();
closegraph();
return 0;
}
Output//
42.) setallpalette
Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
int y = 10;
char msg[80];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
maxcolor = getmaxcolor();
ht = 2 * textheight("W");
getpalette(&pal);
setcolor(color);
outtextxy(1, y, msg);
y += ht;
getch();
setpalette(color, BLACK);
getch();
setallpalette(&pal);
getch();
closegraph();
return 0;
Output//
43.) setaspectratio
Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int xasp, yasp, midx, midy;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
getaspectratio(&xasp, &yasp);
circle(midx, midy, 30);
getch();
cleardevice();
setaspectratio(xasp/2, yasp);
circle(midx, midy, 30);
getch();
cleardevice();
setaspectratio(xasp, yasp/2);
circle(midx, midy, 30);
getch();
closegraph();
return 0;
}
Output//
44.) setbkcolor
Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
char msg[80];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
settextjustify(CENTER_TEXT, CENTER_TEXT);
x = getmaxx() / 2;
y = getmaxy() / 2;
cleardevice();
setbkcolor(bkcol);
if (bkcol == WHITE)
setcolor(EGA_BLUE);
outtextxy(x, y, msg);
getch();
closegraph();
return 0;
Output//
45.) setcolor
Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = EGA, gmode = EGAHI, errorcode;
int color, maxcolor, x, y;
char msg[80]
initgraph(&gdriver, &gmode, "")
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxcolor = getmaxcolor();
settextjustify(CENTER_TEXT, CENTER_TEXT);
x = getmaxx() / 2;
y = getmaxy() / 2;
for (color=1; color<=2; color++)
{
cleardevice();
setcolor(color);
sprintf(msg, "Color: %d", color);
outtextxy(x, y, msg);
getch();
}
closegraph();
return 0;
}
Output//
46.) setfillpattern
Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
char msg[80];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
maxcolor = getmaxcolor();
settextjustify(CENTER_TEXT, CENTER_TEXT);
x = getmaxx() / 2;
y = getmaxy() / 2;
{
cleardevice();
setcolor(color);
outtextxy(x, y, msg);
getch();
closegraph();
return 0;
Output//
47.) setfillstyle
Program
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
};
int main(void)
char stylestr[40];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setfillstyle(style, getmaxcolor());
strcpy(stylestr, fname[style]);
getch();
cleardevice();
getch();
closegraph();
return 0;
Output//
48.) setgraphbufsize
Program
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
};
int main(void)
char stylestr[40];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setfillstyle(style, getmaxcolor());
strcpy(stylestr, fname[style]);
getch();
cleardevice();
getch();
closegraph();
return 0;
Output//
49.) setgraphmode
Program
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
};
int main(void)
char stylestr[40];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setfillstyle(style, getmaxcolor());
strcpy(stylestr, fname[style]);
getch();
cleardevice();
getch();
closegraph();
return 0;
Output//
50.) setlinestyle
Program
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
};
int main(void)
char stylestr[40];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setfillstyle(style, getmaxcolor());
strcpy(stylestr, fname[style]);
getch();
cleardevice();
getch();
closegraph();
return 0;
Output//
51.) setpalette
Program
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
};
int main(void)
char stylestr[40];
errorcode = graphresult();
if (errorcode != grOk)
getch();
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setfillstyle(style, getmaxcolor());
strcpy(stylestr, fname[style]);
getch();
cleardevice();
getch();
closegraph();
return 0;
Output//
52.) setrgbcolor
Syntex: setrgbcolor( int colornum int red int green int blue)
Program
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
"SOLID_FILL",
"LINE_FILL",
"LTSLASH_FILL",
};
int main(void)
char stylestr[40];
errorcode = graphresult();
if (errorcode != grOk)
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setfillstyle(style, getmaxcolor());
strcpy(stylestr, fname[style]);
getch();
cleardevice();
getch();
closegraph();
return 0;
Output//
53.) settextjustify
Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
"CENTER_TEXT",
"RIGHT_TEXT"
};
"CENTER_TEXT",
"RIGHT_TEXT"
};
int main(void)
char msg[80];
errorcode = graphresult();
if (errorcode != grOk)
exit(1);
midx = getmaxx() / 2;
midy = getmaxy() / 2;
cleardevice();
settextjustify(hj, vj);
xat(midx, midy);
getch();
closegraph();
return 0;
Output//