#include<stdio.h>
#include<graphics.h>
#include<math.h>
#define Round(x) ((int)(x+0.5))
void ddaLine(float x1,float y1,float x2,float y2)
{
int dx,dy,length,i=1;
float x=x1,y=y1,xIncr,yIncr;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
length=dx;
else
length=dy;
xIncr=dx/(float)length;
yIncr=dy/(float)length;
putpixel(Round(x),Round(y),RED);
while(i<=length)
{
delay(100);
x+=xIncr;
y+=yIncr;
putpixel(Round(x),Round(y),RED);
i++;
}
}
int main()
{
float x1,y1,x2,y2;
int gdriver = DETECT, gmode, errorcode;
clrscr();
initgraph(&gdriver,&gmode,"C://TurboC3//BGI");
printf("\nEnter the value of x1 :\t");
scanf("%f",&x1);
printf("\nEnter the value of y1 :\t");
scanf("%f",&y1);
printf("\nEnter the value of x2 :\t");
scanf("%f",&x2);
printf("\nEnter the value of y2 :\t");
scanf("%f",&y2);
ddaLine(x1,y1,x2,y2);
getch();
closegraph();
return 0;
}
DDA (Digital Differential Analyzer ) line draw algorithm
Subscribe to:
Posts (Atom)

No comments:
Post a Comment