You are on page 1of 2

Experiment No:2

AIM: Write a Program to implement DDA Line Drawing Algorithm

Program Code:-

#include <stdio.h>
#include<conio.h>
#include <graphics.h>
int main()
{
int count = 1, gd = DETECT, gm;
int x, y, dx, dy, increment;
int x1, y1, x2, y2;
printf("\nEnter the value of x1 AND y1:\t");
scanf("%d", &x1);
scanf("%d", &y1);
printf("\nEnter the value of x2 AND y2:\t");
scanf("%d", &x2);
scanf("%d", &y2);
initgraph(&gd, &gm, "..\\bgi");
dx = abs(x2 - x1);
dy = abs(y2 - y1);
if(dx >= dy)
{
increment = dx;
}
else
{
increment = dy;
}
dx = dx / increment;
dy = dy / increment;
x = x1;
y = y1;
for(count = 1; count <= increment; count++)
{
putpixel(x, y, 4);
x = x + dx;
y = y + dy;
delay(100);
}
getch();
closegraph();
return 0;
}

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

You might also like