Debug the DDA

Status
Not open for further replies.

Plasma_Snake

Indidiot
Below the is the program code for DDA line drawing algorithm. It compiles with no error and runs fine on my college computers but at my home it gives "run time error" which is"BGI Error: Graphics not initialized(use 'initgraph')".:( Resolve it please.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd,gm,x1,x2,y1,y2,xinc,yinc,i,dx,dy,len,x,y;
gd = DETECT;
initgraph(&gd,&gm," ");
printf("enter the coordinates of x1,y1 and x2,y2 ");
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
dx = ( x2-x1 );
dy = ( y2-y1 );
if( dx > dy )
len = abs(dx);
else
len = abs(dy);
xinc = dx/len;
yinc = dy/len;
x = x1;
y = y1;
for(i=1;i<=len;i++)
{ x = x+xinc;
y = y+yinc;
putpixel(x,y,3);
}
getch();
}
 
Status
Not open for further replies.
Top Bottom