The following functions compose the Borland Graphics Interface and are usually available for 16 bit DOS applications. Use them to create onscreen graphics with text. They are defined in graphics.h.
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm; initgraph(&gd,&gm,"f:\\tc\\bgi"); getch(); closegraph(); /* closes down the graphics system */ return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); /* wait for a key */ exit(1); }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } outtext("Welcome to Borland Graphics Interface"); /* output the message */ getch(); closegraph(); return 0; }
//outtextxy #include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } outtextxy(175,250,"Welcome to Borland Graphics Interface"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> //outtextxy int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); outtextxy(175,250,"Welcome to Borland Graphics Interface"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,error,maximumcolor; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } maximumcolor = getmaxcolor(); for (i=0; i<=maximumcolor;i++) { setbkcolor(i); outtextxy(175,250,"Welcome to Borland Graphics Interface"); outtextxy(getmaxx()-250,getmaxy()-40,"www.COnlineCourse.com"); getch(); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,error,maximumcolor; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } maximumcolor = getmaxcolor(); for (i=0; i<=maximumcolor;i++) { setbkcolor(i); sprintf(message, "Background color: %d",i); /* create a message string */ outtextxy(250, 240,message); outtextxy(getmaxx()-250,getmaxy()-40,"www.COnlineCourse.com"); getch(); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,error,maximumcolor; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } maximumcolor = getmaxcolor(); for (i=0; i<=maximumcolor;i++) { cleardevice(); /* clear the screen */ setbkcolor(i); sprintf(message, "Background color: %d",i); outtextxy(250, 240,message); outtextxy(getmaxx()-250,getmaxy()-40,"www.COnlineCourse.com"); getch(); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,error,maximumcolor; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); maximumcolor = getmaxcolor(); for (i=0; i<=maximumcolor;i++) { cleardevice(); setcolor(i); sprintf(message, "Graphics color: %d",i); outtextxy(250, 240,message); outtextxy(getmaxx()-250,getmaxy()-40,"www.COnlineCourse.com"); getch(); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,j=0,error,maximumcolor; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); for (i=1; i<11; i++) { /* select the text style, direction, and size */ settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i); sprintf(message, "Size: %d", i); outtextxy(1,j, message); /* advance to the next text line */ j += textheight(message); } getch(); closegraph(); return 0; }
/* textwidth example */ #include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,j=0,k=0,error,maximumcolor; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); j = getmaxy() / 2; settextjustify(LEFT_TEXT, CENTER_TEXT); for (i = 1; i < 11; i++) { settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i); sprintf(message, "Size: %d", i); outtextxy(k, j, message); /* advance to the end of the text */ k+= textwidth(message); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char range[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); sprintf(range, "X values range from 0..%d", getmaxx()); outtextxy( getmaxx()/2,getmaxy()/2 ,range); outtextxy(getmaxx()-250,getmaxy()-40,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char range[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); sprintf(range, "Y values range from 0..%d", getmaxy()); outtextxy( getmaxx()/2,getmaxy()/2 ,range); outtextxy(getmaxx()-250,getmaxy()-40,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> //delay int main() { int gd=DETECT,gm,error,i; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); for(i=0;i<=getmaxy();i++) { cleardevice(); sprintf(message, ".<<---(x=0,y=%d) :: www.COnlineCourse.com",i); outtextxy( 0,i ,message); delay(100); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> //delay int main() { int gd=DETECT,gm,error,i; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); for(i=0;i<=getmaxx();i++) { cleardevice(); sprintf(message, ".<<---(x=%d,y=10) :: www.COnlineCourse.com",i); outtextxy( i,10 ,message); delay(100); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,error; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); for(i=1;i<=150;i+=10) { cleardevice(); arc (310,250,360-i, (360-i)+150,i); //void arc (int x, int y, int startangle, int endangle, int radius); outtextxy(getmaxx()-200,getmaxy()-100,"Center:(310,250)"); sprintf(message, "Radius : %d",i); outtextxy(getmaxx()-200,getmaxy()-80,message); sprintf(message, "Start angle : %d ",360-i); outtextxy(getmaxx()-200,getmaxy()-60,message); sprintf(message, "End angle : %d",(360-i)+150); outtextxy(getmaxx()-200,getmaxy()-40,message); getch(); } cleardevice(); for(i=1;i<=150;i+=10) arc (310,250,360-i, (360-i)+150,i); outtextxy(getmaxx()-250,getmaxy()-40,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); bar (320,250, 250, 10); outtextxy(getmaxx()-200,getmaxy()-100,"Left : 320"); outtextxy(getmaxx()-200,getmaxy()-80,"Top : 250"); outtextxy(getmaxx()-200,getmaxy()-60,"Right : 250"); outtextxy(getmaxx()-200,getmaxy()-40,"Bottom : 10"); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); bar3d(320,250, 250, 50,35,125); outtextxy(getmaxx()-200,getmaxy()-140,"Left : 250"); outtextxy(getmaxx()-200,getmaxy()-120,"Top : 250"); outtextxy(getmaxx()-200,getmaxy()-100,"Right : 250"); outtextxy(getmaxx()-200,getmaxy()-80,"Bottom : 50"); outtextxy(getmaxx()-200,getmaxy()-60,"Depth : 35"); outtextxy(getmaxx()-200,getmaxy()-40,"Top Flag : 125"); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,error; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); for(i=10;i<=210;i+=10) { cleardevice(); circle (320, 250,i); outtextxy(getmaxx()-200,getmaxy()-60,"Center : (320,250)"); sprintf(message, "Radius : %d",i); outtextxy(getmaxx()-200,getmaxy()-40,message); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); } cleardevice(); for(i=10;i<=210;i+=10) circle (320, 250,i); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; int poly[10],maxx, maxy; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); maxx = getmaxx(); maxy = getmaxy(); poly[0] = 30; /* first vertex */ poly[1] = maxy / 2; poly[2] = maxx - 30; /* second vertex */ poly[3] = 30; poly[4] = maxx - 75; /* third vertex */ poly[5] = maxy - 30; poly[6] = maxx / 2; /* fourth vertex */ poly[7] = maxy / 2; poly[8] = poly[0]; /* drawpoly doesn't automatically close */ poly[9] = poly[1]; /* the polygon, so we close it */ drawpoly(5, poly); /* draw the polygon */ outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,poly[10],maxx, maxy,i,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); maxx = getmaxx(); maxy = getmaxy(); poly[0] = 30; poly[1] = maxy / 2; poly[2] = maxx - 30; poly[3] = 30; poly[4] = maxx - 75; poly[5] = maxy - 30; poly[6] = maxx / 2; poly[7] = maxy / 2; poly[8] = poly[0]; /* drawpoly doesn't automatically close */ poly[9] = poly[1]; for (i=EMPTY_FILL; i
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,i; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); line(0, 0, getmaxx(), getmaxy()); /* draw a line */ outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,j,error; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); for(i=50,j=100;i<=100;i+=10,j+=20) { cleardevice(); ellipse (getmaxx()/2,getmaxy()/2,0,360,j+75, j); //<<<<<<<<< line(getmaxx()/2,getmaxy()/2,(getmaxx()/2)+j+75,getmaxy()/2); line(getmaxx()/2,getmaxy()/2,getmaxx()/2,(getmaxy()/2)-j); sprintf(message, "Center (%d,%d)",getmaxx()/2,getmaxy()/2); outtextxy(getmaxx()-200,getmaxy()-120,message); outtextxy(getmaxx()-200,getmaxy()-100,"Start agle : 0"); outtextxy(getmaxx()-200,getmaxy()-80,"End angle : 360"); sprintf(message, "xradius: %d ",j+75); outtextxy(getmaxx()-200,getmaxy()-60,message); sprintf(message, "yradius : %d",j); outtextxy(getmaxx()-200,getmaxy()-40,message); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); } cleardevice(); for(i=50,j=100;i<=100;i+=10,j+=20) ellipse (getmaxx()/2,getmaxy()/2,0,360,j+75,j); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,i,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); /* loop through the fill patterns */ for (i = EMPTY_FILL; i < USER_FILL; i++) { /* set fill pattern */ setfillstyle(i, getmaxcolor()); /* draw a filled ellipse */ fillellipse(getmaxx() / 2, getmaxy() / 2,200, 150); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* floodfill example */ #include <stdlib.h> int main() { int gd=DETECT,gm,i,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); /* select drawing color */ setfillstyle(SOLID_FILL, getmaxcolor()); /* select fill color */ rectangle(0, 0, getmaxx(), getmaxy()); /* draw a border around the screen */ circle(getmaxx() / 3, getmaxy() /2, 50); circle(getmaxx()-20, 10, 50); circle(100, 100, 50); circle(getmaxx() / 2, 20, 100); circle(getmaxx()-75, getmaxy()-25, 200); circle(20, getmaxy()-20, 25); getch(); floodfill(2, 2, getmaxcolor()); /* fill in bounded region */ outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* getarccoords example */ int main() { int gd=DETECT,gm,error,stangle = 90, endangle = 360; struct arccoordstype info; char message1[80], message2[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); arc(getmaxx() / 2, getmaxy() / 2, stangle, endangle, 100); /* draw arc */ getarccoords(&info); /* convert arc information into strings */ sprintf(message1, "*- (%d, %d)", info.xstart, info.ystart); sprintf(message2, "*- (%d, %d)", info.xend, info.yend); outtextxy(info.xstart, info.ystart, message1); outtextxy(info.xend, info.yend, message2); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* getaspectratio example */ int main() { int gd=DETECT,gm,error,xasp, yasp; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); getaspectratio(&xasp, &yasp); /* get current aspect ratio settings */ circle( getmaxx() / 2, getmaxy() / 2, 100); getch(); cleardevice(); setaspectratio(xasp/2, yasp); circle( getmaxx() / 2, getmaxy() / 2, 100); /* draw wide circle */ getch(); cleardevice(); setaspectratio(xasp, yasp/2); circle( getmaxx() / 2, getmaxy() / 2, 100); getch(); cleardevice(); setaspectratio(xasp, yasp); circle( getmaxx() / 2, getmaxy() / 2, 100); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* getfillpattern example */ int main() { int gd=DETECT,gm,error; char pattern[8] = {0x00, 0x70, 0x20,0x27, 0x25, 0x27, 0x04, 0x04}; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); setfillpattern(pattern,getmaxcolor()); /* select a user-defined fill pattern */ bar(30, 30, getmaxx()-30, getmaxy()-30); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); getfillpattern(pattern); /* get the current user-defined fill pattern */ pattern[0] -= 5; /* alter the pattern we grabbed */ pattern[1] -= 10; pattern[2] += 10; pattern[3] -= 15; setfillpattern(pattern, getmaxcolor()); /* fill the screen with the new pattern */ bar(30, 30, getmaxx()-30, getmaxy()-30); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* getbkcolor example */ int main() { int gd=DETECT,gm,error,color; char name[35]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); settextjustify(CENTER_TEXT, CENTER_TEXT); color = getbkcolor(); itoa(color, name, 10); /* convert color value into a string */ strcat(name, " is the current background color."); /* display a message */ outtextxy(getmaxx() / 2, getmaxy() / 2, name); outtextxy(getmaxx()-125,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> #include/* getpixel example */ #define PIXEL_COUNT 1000 #define DELAY_TIME 100 /* in milliseconds */ int main() { int gd=DETECT,gm,error,i, x, y, color, maxcolor, seed; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); maxcolor = getmaxcolor() + 1; while (!kbhit()) { seed = random(32767); srand(seed); /* seed the random number generator */ for (i=0; i
#include<stdio.h> #include<conio.h> #include<graphics.h> //clearviewport() int main() { int gd=DETECT,gm,error,height; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); height = textheight("l"); outtextxy(0, 0, "* <-- (0, 0) in default viewport"); setviewport(150, 150, getmaxx()-150, getmaxy()-150, 1); /* create a new viewport */ outtextxy(0, 0, "* <-- (0, 0) in new viewport"); outtextxy(0, 2*height, "Press any key to clear viewport:"); getch(); clearviewport(); /* clear the viewport */ outtextxy(0, 0, "Press any key to quit:"); outtextxy(getmaxx()-300,getmaxy()-10,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> //settextjustify int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2, getmaxy() / 2, "Press a key to close the graphics system:"); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); printf("Hi,We're now back in text mode.\n"); printf("Press any key to halt:"); getch(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> //detectgraph #include/* the names of the various cards supported */ char *dname[] = { "requests detection", "a CGA", "an MCGA", "an EGA", "a 64K EGA", "a monochrome EGA", "an IBM 8514", "a Hercules monochrome", "an AT&T 6300 PC", "a VGA", "an IBM 3270 PC" }; int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); clrscr(); printf("You have %s video display card.\n", dname[gd]); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); printf("Press any key to halt:"); getch(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* getcolor example */ int main() { int gd=DETECT,gm,error; int color, midx, midy; char colname[35]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); settextjustify(CENTER_TEXT, CENTER_TEXT); color = getcolor(); /* get the current drawing color */ itoa(color, colname, 10); /* convert color value into a string */ strcat(colname, " is the current drawing color."); outtextxy(getmaxx() / 2, getmaxy() / 2, colname); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* getdrivername example */ int main() { int gd=DETECT,gm,error; char *drivername; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setcolor(getmaxcolor()); drivername = getdrivername(); /* get the name of the device driver in use */ settextjustify(CENTER_TEXT, CENTER_TEXT); strcat(drivername," is currently loaded driver"); outtextxy(getmaxx() / 2, getmaxy() / 2, drivername); /* output the name of the driver */ outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; struct fillsettingstype fillinfo; char message1[50], message2[50]; char *fillname[] = { "EMPTY_FILL", "SOLID_FILL", "LINE_FILL", "LTSLASH_FILL", "SLASH_FILL","BKSLASH_FILL", "LTBKSLASH_FILL", "HATCH_FILL", "XHATCH_FILL", "INTERLEAVE_FILL", "WIDE_DOT_FILL", "CLOSE_DOT_FILL", "USER_FILL" }; /* The names of the fill styles supported */ initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); getfillsettings(&fillinfo); /* get info about current fill pattern and color */ sprintf(message1, "%s is the fill style.", fillname[fillinfo.pattern]); sprintf(message2, "%d is the fill color.", fillinfo.color); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2, (getmaxy() / 2)-2*textheight("l"), message1); outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("l"), message2); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,mode; char strnumber[80], strmode[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); mode = getgraphmode(); /* get mode number and name strings */ sprintf(strnumber, "%d is the current mode number.", mode); sprintf(strmode, "%s is the current graphics mode.", getmodename(mode)); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2, getmaxy() / 2, strnumber); outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("l"), strmode); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; struct linesettingstype lineinfo; char linestyle[80], linepattern[80], linewidth[80]; char *linename[] = { "SOLID_LINE", "DOTTED_LINE", "CENTER_LINE", "DASHED_LINE", "USERBIT_LINE" }; /* the names of the line styles supported */ initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); getlinesettings(&lineinfo); /* get information about current line settings */ sprintf(linestyle, "%s is the line style.", linename[lineinfo.linestyle]); /* convert line information into strings */ sprintf(linepattern, "0x%X is the user-defined line pattern.",lineinfo.upattern); sprintf(linewidth, "%d is the line thickness.", lineinfo.thickness); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2,getmaxy() / 2, linestyle); outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("l"), linepattern); outtextxy(getmaxx() / 2, (getmaxy() / 2)+4*textheight("l"), linewidth); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char colstr[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); /* grab the color info. and convert it to a string */ settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2,getmaxy() / 2, colstr); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char modestr[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); sprintf(modestr, "This driver supports modes 0..%d",getmaxmode()); /* grab the mode info. and convert it to a string */ settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2,getmaxy() / 2, modestr); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,mode; char strnumber[80], strmode[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); mode = getgraphmode(); /* get mode number and name strings */ sprintf(strnumber, "%d is the current mode number.", mode); sprintf(strmode, "%s is the current graphics mode.",getmodename(mode)); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2, getmaxy() / 2, strnumber); outtextxy(getmaxx() / 2, (getmaxy() / 2)+2*textheight("W"), strmode); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setwritemode(XOR_PUT); /* select XOR drawing mode */ line(0, 0, getmaxx(), getmaxy()); getch(); line(0, 0, getmaxx(), getmaxy()); /* erase the line by drawing over it */ getch(); setwritemode(COPY_PUT); /* select overwrite drawing mode */ line(0, 0, getmaxx(), getmaxy()); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gdriver = EGA, gmode = EGAHI, error,height; initgraph(&gdriver,&gmode,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); height = textheight("l"); setactivepage(1); /* select the off screen page for drawing */ circle(getmaxx()/2,getmaxy()/2,150); /* draw a circle on page #1 */ settextjustify(CENTER_TEXT, CENTER_TEXT); /* output a message on page #1 */ outtextxy(getmaxx() / 2, getmaxy() / 2, "This is page #1:"); outtextxy(getmaxx() / 2, (getmaxy() / 2)+height, "Press any key to halt:"); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); setactivepage(0); /* select drawing to page #0 */ ellipse (getmaxx()/2,getmaxy()/2,0,360,150, 100); outtextxy(getmaxx() / 2, getmaxy() / 2, "This is page #0."); outtextxy(getmaxx() / 2, (getmaxy() / 2)+height, "Press any key to view page #1:"); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); /* select page #1 as the visible page */ setvisualpage(1); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,a,b,result; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); circle(getmaxx()/2,getmaxy()/2,175); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2, getmaxy() / 2, "Press a key to close the graphics system:"); getch(); closegraph(); /* closes down the graphics system */ printf("*****We're now back in text mode.*****\n\n"); printf("Enter two numbers\n"); scanf("%d%d",&a,&b); result=a+b; printf("\nSum of %d and %d is %d\n\nOK!",a,b,result); getch(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,i; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); moveto(getmaxx() / 2, getmaxy() / 2); /* move to the text starting position */ outtext("Norm "); setusercharsize(1, 2, 1, 1); outtext("Short "); /* make the text 1/2 the normal width */ setusercharsize(3, 1, 1, 1); outtext("Wide"); /* make the text 3 times normal width */ settextstyle(GOTHIC_FONT, HORIZ_DIR, 1); outtextxy(getmaxx()/2,getmaxy()-30,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* the names of the text styles supported */ char *styles[] = { "DEFAULT font", "TRIPLEX font", "SMALL font", "SANS SERIF_font", "GOTHIC_font", "SCRIPT font","SIMPLEX font", "TRIPLEX SCRIPT font","COMPLEX font", "EUROPEAN font","BOLD font"}; int main() { int gd=DETECT,gm,error,i,style,size = 1; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); settextjustify(CENTER_TEXT, CENTER_TEXT); for (i=DEFAULT_FONT; i<=BOLD_FONT; i++) /* loop through the available text styles */ { cleardevice(); if (i == TRIPLEX_FONT) size = 3; settextstyle(i, HORIZ_DIR, size); /* select the text style */ outtextxy( getmaxx() / 2, getmaxy() / 2,styles[i]); outtextxy(getmaxx()-250,getmaxy()-25,"www.COnlineCourse.com"); getch(); } closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,i, height, j=0; struct palettetype type; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); getpalette(&type); /* grab a copy of the palette */ for (i=0; i
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,x,y; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); x=getmaxx() / 2; y=getmaxy() / 2; settextjustify(CENTER_TEXT, CENTER_TEXT); rectangle(x-175, y-50, x+175, y+50); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); outtextxy(x, y, "Press any key to exit graphics"); getch(); restorecrtmode(); /* restore system to text mode */ printf("We're now in text mode.\n"); printf("Press any key to return to graphics mode:"); getch(); setgraphmode(getgraphmode()); /* return to graphics mode */ settextjustify(CENTER_TEXT, CENTER_TEXT); setbkcolor(BLUE); outtextxy(x, y, "We're back in graphics mode."); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); outtextxy(x, y+2*textheight("l"), "Press any key to return to text mode:"); getch(); restorecrtmode(); /* restore system to text mode */ printf("We're now in text mode.\n"); printf("Press any key to halt:"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> char *linename[] = { "SOLID_LINES", "DOTTED_LINES", "CENTER_LINES","DASHED_LINES", "USERBIT_LINES" }; /* The names of the line styles supported */ int main() { int gd=DETECT,gm,error,i; int style, midx, midy, userpat; char stylename[25],message[25]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); midx = getmaxx() / 2; midy = getmaxy() / 2; userpat = 1; for(i=1;i<=3;i++) { for (style=SOLID_LINE; style<=USERBIT_LINE; style++) { sprintf(message, "Line thickness : %d",i); outtextxy(midx-75, midy-100, message); setlinestyle(style, userpat, i); /* select the line style */ strcpy(stylename, linename[style]); /* convert style into a string */ rectangle(10, 10, getmaxx()-10, getmaxy()-10); line(10, 10, midx-10, midy); line(midx-10, midy, getmaxx()-10,getmaxy()-10); line(midx-10, midy, getmaxx()-10,10); line(midx-10, midy,10,getmaxy()-10); outtextxy(midx, midy, stylename); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); cleardevice(); } getch(); } closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error, color, maxcolor, height,y = 10; char msg[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); maxcolor = getmaxcolor(); height = 2 * textheight("l"); for (color=1; color<=maxcolor; color++) /* display the default colors */ { setcolor(color); sprintf(msg, "Color: %d", color); outtextxy((getmaxx()/2)-50, y, msg); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); y += height; } getch(); for (color=1; color<=maxcolor; color++) /* red out the colors one by one */ { setpalette(color, RED); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); } closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> #define BUFSIZE 1000 /* internal graphics buffer size */ int main() { int gd=DETECT,gm,i,error; int x, y, oldsize; char msg[80]; oldsize = setgraphbufsize(BUFSIZE); /* Set size of internal graphics buffer before calling initgraph*/ initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); x = getmaxx() / 2; y = getmaxy() / 2; sprintf(msg, "Graphics buffer size: %d", BUFSIZE); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(x, y-25, msg); sprintf(msg, "Old graphics buffer size: %d", oldsize); outtextxy(x, y+2*textheight("l"), msg); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* the names of the fill styles supported */ char *fname[] = { "EMPTY_FILL", "SOLID_FILL", "LINE_FILL", "LTSLASH_FILL", "SLASH_FILL", "BKSLASH_FILL", "LTBKSLASH_FILL","HATCH_FILL", "XHATCH_FILL", "INTERLEAVE_FILL", "WIDE_DOT_FILL", "CLOSE_DOT_FILL", "USER_FILL" }; int main() { int gd=DETECT,gm,error,i; int style, midx, midy; char stylestr[40]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); midx = getmaxx() / 2; midy = getmaxy() / 2; for (style = EMPTY_FILL; style < USER_FILL; style++) { setfillstyle(style, getmaxcolor()); /* select the fill style */ strcpy(stylestr, fname[style]); /* convert style into a string */ /* fill a bar */ bar3d(midx-125, midy-125, midx+10, midy, 10, 10); outtextxy(midx+10, midy, stylestr); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); cleardevice(); } getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,left, top, right, bottom; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); left = getmaxx() / 2 -200; top = getmaxy() / 2 - 200; right = getmaxx() / 2 + 200; bottom = getmaxy() / 2 + 200; rectangle(left,top,right,bottom); /* draw a rectangle */ outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error, midx, midy, i; int stangle = 0, endangle = 270, xrad = 200, yrad = 150; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); midx = getmaxx() / 2; midy = getmaxy() / 2; for (i=EMPTY_FILL; i
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,low, high; char moderange[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); getmoderange(gd, &low, &high); /* get the mode range for this driver */ sprintf(moderange, "This driver supports modes %d..%d", low, high); /* convert mode range info. into strings */ settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2, getmaxy() / 2, moderange); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char palettesize[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); sprintf(palettesize, "The palette has %d modifiable entries.",getpalettesize()); /* convert palette size info into string */ settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(getmaxx() / 2, getmaxy() / 2, palettesize); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,i,j = 10,height; struct palettetype pal; char palettesize[80], paletteval[20]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); getpalette(&pal); /* grab a copy of the palette */ sprintf(palettesize, "The palette has %d modifiable entries.",pal.size); /* convert palette info into strings */ outtextxy(getmaxx()/2-175, j, palettesize); if (pal.size != 0) { height = textheight("l"); j += 2*height; outtextxy(getmaxx()/2-125, j, "Here are the current values:"); j += 2*height; for (i=0; i
#include<stdio.h> #include<conio.h> #include<graphics.h> char *clip[] = { "OFF", "ON" }; int main() { int gd=DETECT,gm,error, midx, midy, ht; struct viewporttype viewinfo; char topstr[80], botstr[80], clipstr[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); midx = getmaxx() / 2; midy = getmaxy() / 2; getviewsettings(&viewinfo); /* get information about current viewport */ sprintf(topstr, "(%d, %d) is the upper left viewport corner.",viewinfo.left, viewinfo.top); sprintf(botstr, "(%d, %d) is the lower right viewport corner.",viewinfo.right, viewinfo.bottom); sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); settextjustify(CENTER_TEXT, CENTER_TEXT); ht = textheight("W"); outtextxy(midx, midy, topstr); outtextxy(midx, midy+2*ht, botstr); outtextxy(midx, midy+4*ht, clipstr); outtextxy(getmaxx()-150,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,i; char msg[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); moveto(getmaxx() / 2, getmaxy() / 2); /* move to the screen center point */ sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); outtext(msg); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char msg[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); moveto(getmaxx() / 2-100, getmaxy() / 2+25); /* move to the screen center point */ sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); outtext(msg); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setlinestyle(DOTTED_LINE, 0, 3); rectangle(10, 10, getmaxx()-10,getmaxy()-10); outtextxy(getmaxx()/2-100, getmaxx()/3, "Before default values are restored."); outtextxy(getmaxx()-250,getmaxy()-30,"www.COnlineCourse.com"); getch(); graphdefaults(); /* restore default values for everything */ cleardevice(); rectangle(10, 10, getmaxx()-10,getmaxy()-10); /* output rectangle with default settings */ outtextxy(getmaxx()/2-100, getmaxy()/3, "After restoring default values."); outtextxy(getmaxx()-250,getmaxy()-30,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> #define NONSENSE -50 int main() { int gd=NONSENSE,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error: %s\n", grapherrormsg(error)); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); rectangle(10, 10, getmaxx()-10,getmaxy()-10); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> #define ARROW_SIZE 10 void draw_arrow(int x, int y); int main() { int gd=DETECT,gm,error,i; void *arrow; int x, y, maxx; unsigned int size; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); maxx = getmaxx(); x = 0; y = getmaxy() / 2; draw_arrow(x, y); /* draw the image to be grabbed */ size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); /* calculate the size of the image */ arrow = malloc(size); /* allocate memory to hold the image */ getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); /* grab the image */ while (!kbhit()) /* repeat until a key is pressed */ { putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); /* erase old image */ x += ARROW_SIZE; if (x >= maxx) x = 0; putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); /* plot new image */ outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); } free(arrow); closegraph(); return 0; } void draw_arrow(int x, int y) { moveto(x, y); /* draw an arrow on the screen */ linerel(4*ARROW_SIZE, 0); linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); linerel(0, 2*ARROW_SIZE); linerel(2*ARROW_SIZE, -1*ARROW_SIZE); }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char message[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); moveto(100,100); /* move the CP to location (100,100) */ sprintf(message, " (%d, %d)", getx(), gety()); /* create and output a message at (100,100) */ outtextxy(100,100, message); linerel(200, 200); /* draw line to a point a relative distance away from current CP*/ sprintf(message, " (%d, %d)", getx(), gety()); /* create and output a message at CP */ outtext(message); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error; char msg[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); moveto(100, 100); /* move the CP to location (100,100) */ sprintf(msg, " (%d, %d)", getx(), gety()); /* create and output a message at (100,100) */ outtextxy(100,100, msg); lineto(200, 200); /* draw a line to (100,100) */ sprintf(msg, " (%d, %d)", getx(), gety()); /* create and output a message at CP */ outtext(msg); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> /* moverel example */ int main() { int gd=DETECT,gm,error; char msg[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); moveto(100,100); putpixel(getx(), gety(), getmaxcolor()); /* plot a pixel at the CP */ sprintf(msg, " (%d, %d)", getx(), gety()); outtextxy(100,100, msg); moverel(200, 200); putpixel(getx(), gety(), getmaxcolor()); /* plot a pixel at the CP */ sprintf(msg, " (%d, %d)", getx(), gety()); /* create and output a message at CP */ outtext(msg); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,i; char msg[80]; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); moveto(100,100); putpixel(getx(), gety(), getmaxcolor()); sprintf(msg, " (%d, %d)", getx(), gety()); outtextxy(100,100, msg); moveto(200,200); putpixel(getx(), gety(), getmaxcolor()); sprintf(msg, " (%d, %d)", getx(), gety()); outtext(msg); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT,gm,error,stangle = 45, endangle = 135, radius = 200; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); setfillstyle(EMPTY_FILL, getmaxcolor()); /* set fill style and draw a pie slice */ pieslice(getmaxx() / 2, getmaxy() / 2, stangle, endangle, radius); outtextxy(getmaxx()-250,getmaxy()-20,"www.COnlineCourse.com"); getch(); closegraph(); return 0; }
#include<stdio.h> #include<conio.h> #include<graphics.h> //outtext int main() { int gd=DETECT,gm,error; initgraph(&gd,&gm,"f:\\tc\\bgi"); error = graphresult(); if (error != grOk) { printf("Graphics error occurred"); printf("Press any key to halt:"); getch(); exit(1); } setbkcolor(BLUE); for (i=SOLID_FILL; i