A function in Borland's graphics library in TurboC; switches to graphics mode.
Platform-dependent. For Turbo C, enter initgraph and press Ctrl+F1.
because initgraph() automatically detect current available graphmode and load it on to the graphdriver.
Initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode.Initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graphresult to 0.
At the beginning in the header file: #include <graphics.h>
#include#include#includevoid main(){int gd=DETECT,gm=4,i;initgraph(&gd,&gm,"c:\\tc\\bgi");setcolor(3);for(i=0;i
The initgraph() is a method that you always use when you want to write graphic programming in C++. It is used to initial graphi window before something can be drawn on the window.
Platform-dependent. For Turbo C, enter initgraph and press Ctrl+F1.
because initgraph() automatically detect current available graphmode and load it on to the graphdriver.
Initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode.Initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graphresult to 0.
At the beginning in the header file: #include <graphics.h>
BGI stands for Borland Graphics Interface. These are the files that contains the information about the graphic functions to be used. These are responsible for performing graphic operations under dos. In Borland turbo c++ these files are contained in directory. -> c:\tc\bgi By default these are loaded in the current directory while compiling and executing the program under c/c++ but sometimes we need to specify their path in "initgraph() function. like: initgrapy(&gdriver,&gmode,"c:\\tc\\bgi"); otherwise it will display you error about bgi.
Here, maybe a few other shapes as well#include#includevoid main(){int gd=DETECT, gm;int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };initgraph(&gd, &gm, "");circle(100,100,50);outtextxy(75,170, "Circle");rectangle(200,50,350,150);outtextxy(240, 170, "Rectangle");ellipse(500, 100,0,360, 100,50);outtextxy(480, 170, "Ellipse");line(100,250,540,250);outtextxy(300,260,"Line");sector(150, 400, 30, 300, 100,50);outtextxy(120, 460, "Sector");drawpoly(6, poly);outtextxy(340, 460, "Polygon");getch();closegraph();}
#include#include#includevoid main(){int gd=DETECT,gm=4,i;initgraph(&gd,&gm,"c:\\tc\\bgi");setcolor(3);for(i=0;i
int main() { int gd = DETECT, gm; int midx, midy; initgraph(&gd, &gm, "C:\TC\BGI"); setcolor(MAGENTA); rectangle(0,40,639,450); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); setcolor(WHITE); outtextxy(275,10,"Pie Chart"); midx = getmaxx()/2; midy = getmaxy()/2; setfillstyle(LINE_FILL,BLUE); pieslice(midx, midy, 0, 75, 100); outtextxy(midx+100, midy - 75, "20.83%"); setfillstyle(XHATCH_FILL,RED); pieslice(midx, midy, 75, 225, 100); outtextxy(midx-175, midy - 75, "41.67%"); setfillstyle(WIDE_DOT_FILL,GREEN); pieslice(midx, midy, 225, 360, 100); outtextxy(midx+75, midy + 75, "37.50%"); getch(); return 0; }
: #include<graphics.h> #include<stdio.h> #include<conio.h> #include<alloc.h> #include<math.h> #include<dos.h> const pi=3.14; void main() {int gd=DETECT, gm,i,x,y; int size; void *buf; initgraph(&gd,&gm,"c:\\tc\\bgi"); ellipse(240,210,0,160,90,45); ellipse(240,190,180,360,90,45); circle(170,195,3); ellipse(100,230,10,400,100,80); ellipse(232,207,0,365,100,150); arc(265,170,0,160,15); arc(225,233,180,350,20); arc(265,233,180,380,10); size=imagesize(150,150,350,350); buf=(char *)malloc(size); getimage(150,150,350,350,buf); for(i=0;i<=360;i+=2) {delay(10); cleardevice(); x=150*cos(i*pi/180); y=150*sin(i*pi/180); putimage(200+x,100+y,buf,0); } getch(); restorecrtmode();}
Here is the C code for DDA line drawing... #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> void main() { int gd, gm; float x, y, dx, dy, len; int x1, y1, x2, y2, i; detectgraph(&gd, &gm); initgraph(&gd, &gm,""); printf("\n Enter the coordinates of line : "); scanf("%d %d %d %d", &x1, &y1, &x2, &y2); dx = abs(x2-x1); dy = abs(y2-y1); if (dx >= dy) len = dx; else len = dy; dx = (x2-x1)/len; dy = (y2-y1)/len; x = x1 + 0.5; y = y1 + 0.5; i = 1; while (i <= len) { putpixel(x, y, 6); x = x+dx; y = y+dy; i++; } getch(); } -Suraj.
//reflection for triangle # include <iostream.h> # include <conio.h> # include <graphics.h> # include <math.h> char IncFlag; int PolygonPoints[3][2] = {{10,100},{110,100},{110,200}}; void PolyLine() { int iCnt; cleardevice(); line(0,240,640,240); line(320,0,320,480); for (iCnt=0; iCnt<3; iCnt++) { line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1], PolygonPoints[(iCnt+1)%3][0],PolygonPoints[(iCnt+1)%3][1]); } } void Reflect() { float Angle; int iCnt; int Tx,Ty; cout<<endl; for (iCnt=0; iCnt<3; iCnt++) PolygonPoints[iCnt][1] = (480 - PolygonPoints[iCnt][1]); } void main() { int gDriver = DETECT, gMode; int iCnt; initgraph(&gDriver, &gMode, "C:\\TC\\BGI"); for (iCnt=0; iCnt<3; iCnt++) { PolygonPoints[iCnt][0] += 320; PolygonPoints[iCnt][1] = 240 - PolygonPoints[iCnt][1]; } PolyLine(); getch(); Reflect(); PolyLine(); getch(); }