Computer Graphics & Multimedia (DCO-511)
Computer Graphics & Multimedia (DCO-511)
(DCO-511)
Submitted by:
SAUD AHMAD KHAN
Roll No.-16-DCS_055
Diploma in Computer Engineering- V Semester
x = getmaxx() / 2;
y = getmaxy() / 2;
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, msg);
sprintf(msg, "Old graphics buffer size: %d", oldsize);
outtextxy(x, y+textheight("W"), msg);
getch();
closegraph();
}
OUTPUT
Registerfarbgifont()
Declaration: int Registerfarbgifont(void (*font)(void));
int Registerfarbgifont(void (*font)(void));
Source code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
errorcode = registerbgifont(triplex_font);
if (errorcode < 0)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
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;
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy, "The TRIPLEX FONT");
getch();
closegraph();
}
Output
Setactivepage(): setactivepage set the active page for graphics output
Syntax: void far setactivepage(int page)
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int gdriver = EGA, gmode = EGAHI;
int x, y, ht;
initgraph(&gdriver, &gmode, "");
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();
}
Setrgbpalette()
Defines colors for IBM-8514 and EVGA graphics cards.
Syntax:- setrgbpalette(int colornum,int red,int green,int blue)
Source code
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver = VGA, gmode = VGAHI;
struct palettetype p;
int i, ht, y, xmax;
initgraph(&gdriver, &gmode, "");
getpalette(&p);
for (i=0; i<p.size; i++)
setrgbpalette(p.colors[i], i*4, i*4, i*4);
ht = getmaxy() /10 ;
xmax = getmaxx();
y = 0;
for (i=0; i<p.size; i++)
{
setfillstyle(SOLID_FILL, i);
bar(0, y, xmax, y+ht);
y += ht;
} getch(); closegraph(); return 0;
}
OUTPUT
Settextjustify()
Sets text justification for graphics mode
Syntax:- void settextjustify(int horiz, int vert)
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#define BUFSIZE 1000
int main()
{
int gdriver = DETECT, gmode;
int x, y, oldsize;
char msg[80];
oldsize = setgraphbufsize(BUFSIZE);
initgraph(&gdriver, &gmode, "");
x = getmaxx() / 2;
y = getmaxy() / 2;
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, msg);
sprintf(msg, "Old graphics buffer size: %d", oldsize);
getch();
closegraph();
return 0;
}
OUTPUT
Setallpalette()
Setallpalette changes all palette colors as specified.
Syntax: - void setallpalette(struct palettetype far *palette)
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = DETECT, gmode;
struct palettetype pal;
int color, maxcolor, ht;
int y = 10;
char msg[80];
initgraph(&gdriver, &gmode, "");
maxcolor = getmaxcolor();
ht = 2 * textheight("W");
getpalette(&pal);
for (color=1; color<=maxcolor; color++)
{
setcolor(color);
sprintf(msg, "Color: %d", color
outtextxy(1, y, msg);
y += ht;
}
setallpalette(&pal);
getch();
closegraph();
return 0;
}
OUTPUT
Graphgetmem()
Syntax: - void far *far _graphgetmem(unsined size)
Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
int main()
{
int gdriver = DETECT, gmode;
clrscr();
initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");
getch();
closegraph();
return 0;
}
void far * far _graphgetmem(unsigned size)
{
printf("_graphgetmem called to allocate %d bytes.\n", size);
getch();
printf("\n");
return farmalloc(size);
}
OUTPUT
Textheight()
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int gdriver = DETECT, gmode,text;
char array[100];
outtextxy(50,60,array);
getch();
}
OUTPUT
Graphresult()
Syntax: - void far *far _graphgetmem(unsined size)
Source code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
int main()
{
int gdriver = DETECT, gmode, errorcode;
clrscr(); getch(); clrscr();
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
getch();closegraph();
return 0;
}
void far * far _graphgetmem(unsigned size)
{
printf("_graphgetmem called to allocate %d bytes.\n", size);
printf("press any key:");
getch();
printf("\n");
return farmalloc(size);
}
OUTPUT
Installuserfont()
Loads a font file (.CHR) that is not built into the BGI system
Syntax :- int installuserfont(char far *name)
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver = DETECT, gmode;
int userfont;
int midx, midy;
initgraph(&gdriver, &gmode, "");
midx = getmaxx() / 2;
midy = getmaxy() / 2;
userfont = installuserfont("USER.CHR");
settextstyle(userfont, HORIZ_DIR, 4);
outtextxy(midx, midy, "Testing!");
getch();
closegraph();
return 0;
}
OUTPUT
Setusercharsize()
User-defined character magnification factor for stroked fonts
Syntax:- void setusercharsize(int multx, int divx, int multy, int divy)
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4);
moveto(0, getmaxy() / 2);
outtext("Normal");
setusercharsize(1, 3, 1, 1);
outtext(" Short using setusercahrsize");
setusercharsize(3, 1, 2, 1);
outtext(" Wide using setusercahrsize");
getch();
closegraph();
return 0;
}
OUTPUT
Setaspectratio()
Setaspectratio sets the graphics aspect ratio
Syntax: - void far setaspectratio(int xasp, int yasp)
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int gdriver = DETECT, gmode;
int xasp, yasp, midx, midy;
initgraph(&gdriver, &gmode, "");
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
getaspectratio(&xasp, &yasp);
circle(midx, midy, 50);
getch();
cleardevice();
setaspectratio(xasp/2, yasp);
circle(midx, midy,50);
getch();
cleardevice();
setaspectratio(xasp, yasp/2);
circle(midx, midy, 50);
getch();
closegraph();
return 0;}
OUTPUT
Getmodename()
Syntax: char *getmodename(int mode_number)
Source code:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int gdriver = DETECT, gmode, errorcode;
int midx, midy, mode;
char numname[80], modename[80];
initgraph(&gdriver, &gmode, "");
midx = getmaxx() / 2;
midy = getmaxy() / 2;
mode = getgraphmode();
sprintf(numname, "%d is the current mode number.", mode);
sprintf(modename, "%s is the current graphics mode.",getmodename(mode));
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy, numname);
outtextxy(midx, midy+2*textheight("W"), modename);
getch();
closegraph();
return 0;
}
OUTPUT
Imagesize()
Syntax: unsigned int imagesize(int left, int top,int right, int bottom);
where,left, top, right, and bottom define the area of the screen in which image is stored.
Source code:
#include <graphics.h>
#include <stdio.h>
void main()
{
int gdriver = DETECT, gmode;
char size[100];
initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");
circle(50, 200, 50);
img = imagesize(150, 150, 250, 250);
sprintf(size, "Size of the Image = %d",img);
outtextxy(20, 280, size);
getch();
}
OUTPUT
Setwritemode: Sets the writing mode for line drawing in graphics mode
Syntax: void far setwritemode(int mode);
Source code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
xmax = getmaxx();
ymax = getmaxy();
setwritemode(XOR_PUT);
line(0, 0, xmax, ymax);
getch();
line(0, 0, xmax, ymax);
getch();
setwritemode(COPY_PUT);
line(0, 0, xmax, ymax);
getch();
closegraph();
}
Setvisualpage:
setactivepage sets the active page for graphics output
setvisualpage sets the visual graphics page number
Syntax:
void far setactivepage(int page);
void far setvisualpage(int page);
Source code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void main
{
select a driver and mode that supports multiple pages.
int gdriver = EGA, gmode = EGAHI;
int x, y, ht;
initgraph(&gdriver, &gmode, "");
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();
}
Output
COMPUTER GRAPHICS & MULTIMEDIA
(DCO-511)
Submitted by:
UMAIR RIAZ
Roll No.-16-DCS_067
Diploma in Computer Engineering- V Semester