/* DDA LINE DRAWING */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define round(a) ((int)(a+0.5))
void main()
{
int gd=DETECT,gm,x1,y1,x2,y2,dx,dy,length,i;
float xinc,yinc,x,y;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter the end point co ordinates of lines");
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
x=x1;
y=y1;
dx=x2-x2;
dy=y2-y1;
if(abs(dx)>abs(dy))
{
length=abs(dx);
}
else
{
length=abs(dy);
}
xinc=dx/(float)length;
yinc=dy/(float)length;
putpixel(round(x),round(y),RED);
for(i=0;i<length;i++)
{
x=x+xinc;
y=y+yinc;
putpixel(round(x),round(y),RED);
}
getch();
}
No comments:
Post a Comment