DDA LINE DRAWING PROGRAM IN C

 DDA LINE DRAWING PROGRAM IN C

Similar Programs

//***PROGRAM FOR DDA LINE DRAWING ALGORITHM***//

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<process.h>
#include<math.h>
#define ROUND(a) ((int)(a+1))
void lineDDA(int xa,int ya, int xb, int yb)
{
int dx= xb-xa, dy=yb-ya,steps, k;
float xIncrement,yIncrement,x=xa,y=ya;
if(abs(dx)>abs(dy)) steps= abs(dx);
else steps= abs (dy);
xIncrement = dx/(float) steps;
yIncrement = dy/(float) steps;
putpixel (ROUND(x),ROUND (y),5);
for (k=0;k<steps;k++)
{
x+=xIncrement;
y+=yIncrement;
putpixel(ROUND(x),ROUND(y),5);
}
}

void main()
{
int a1,a2,b1,b2;
int gdriver= DETECT, gmode;
initgraph (&gdriver,&gmode,"c:\tc\bgi");
printf("ENTER THE STARTING POSITION");
scanf("%d%d",&a1,&a2);
printf("ENTER THE ENDING POSITION");
scanf("%d%d",&b1,&b2);
lineDDA(a1,b1,a2,b2);
getch();
closegraph();
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *