Complete C Program to Generate a Line using Digital differential Algorithm(DDA)
# include<stdio.h>
# include<conio.h>
# include <graphics.h>
# include<math.h>
/*function for plotting the point and drawing the line */
void ddaline(float x1,float y1,float x2,float y2)
{
int i, color=5;
float x,y, xinc, yinc, steps;
steps=ads(x2-x1);
if (steps<abs(y2-y1);
steps=abs(y2-y1);
xinc=(x2-x1)/steps;
yinc=(y2-y1)/steps;
x=x1;
y=y1;
putpixel((int)x,(int)y,color);
for(i=1;i<=steps; i++)
{
putpixel((int)x,(int)y,color); /* plots the points with specified color */
x=x+xinc;
y=y=yinc;
}
{
/* The main program that inputs line end point and passes them to ddaline()
function */
void main()
{
int gd=DETECT,gm,color:
float x1,y1,x2,y2;
printf(“\n enter the end points:\n”);
scanf(“%f %f %f %f”,&x1,&y1,&x2,&y2);
clrscr();
initgraph(&gd,&gm, “c:\\tc\\bgi”);
ddaline(x1,y1,x2,y2);
getch();
closegraph();
}