#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
main()
{
int x1,y1,x2,y2;
int gd=DETECT,gm;
clrscr();
printf("...........DDA Line Drawing Algorithm...........\n");
printf("Enter starting co-ordinates : ");
scanf("%d%d",&x1,&y1);
printf("Enter ending co-ordinates : ");
scanf("%d%d",&x2,&y2);
initgraph(&gd,&gm,"");
dda(x1,y1,x2,y2);
getch();
return 0;
}
dda(int x1,int y1,int x2,int y2)
{
float dx,dy,step,k;
float xinc,yinc,x,y;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
step=abs(dx);
else
step=abs(dy);
xinc=dx/(float)step;
yinc=dy/(float)step;
x=x1;
y=y1;
putpixel(x,y,RED);
for(k=1;k<step;k++)
{
x+=xinc;
y+=yinc;
putpixel(x,y,RED);
}
}
No comments:
Post a Comment