// C program for DDA line generation
#include<stdio.h>
#include<graphics.h>
int abs (int n)
{
return ( (n>0) ? n : ( n * (-1)));
}
void DDA(int X0, int Y0, int X1, int Y1)
{
int dx,dy,steps,i;
float Xinc,Yinc,X,Y;
dx = X1 - X0;
dy = Y1 - Y0;
steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
Xinc = dx / (float) steps;
Yinc = dy / (float) steps;
X = X0;
Y = Y0;
for (i = 0; i <= steps; i++)
{
putpixel (X,Y,YELLOW);
X += Xinc;
Y += Yinc;
delay(50);
}
}
void main()
{
int gd = DETECT, gm;
initgraph (&gd, &gm, "C:\\TurboC3\\BGI");
DDA(100, 100, 300, 100);
getch();
DDA(300, 100, 300, 300);
getch();
DDA(300, 300, 100, 300);
getch();
DDA(100, 300, 100, 100);
getch();
DDA(100, 100, 300, 300);
getch();
DDA(300, 100, 100, 300);
getch();
closegraph();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.