#include "stdio.h"
#include "conio.h"
#include "graphics.h"
#include "math.h"
void dda (float x1,float y1,float x2,float y2)
{
float delx,dely,length;
int x,y,i;
if (x1==x2 && y1==y2)
{
printf ("The line cannot be drawn");
return;
}
else
{
delx = fabs (x2-x1);
dely = fabs (y2-y1);
}
if (delx >= dely)
{
length = delx;
}
else
{
length = dely;
}
delx = (x2-x1)/length;
dely = (y2-y1)/length;
x = x1 + 0.5;
y = x2 + 0.5;
i=1;
while (i <= length)
{
putpixel (x,y,14);
x = x + delx;
y = y + dely;
i = i + 1;
}
}
void main ()
{
int gd,gm;
float x1,y1,x2,y2;
clrscr ();
printf ("Enter the starting points: ");
scanf ("%f%f",&x1,&y1);
printf ("Enter the ending points: ");
scanf ("%f%f",&x2,&y2);
detectgraph (&gd,&gm);
initgraph (&gd,&gm,"c:\\TC\\BGI");
dda (x1,y1,x2,y2);
getch ();
closegraph ();
}
0 comments:
Post a Comment