0% found this document useful (0 votes)
31 views

Experiment No:2: AIM: Write A Program To Implement DDA Line Drawing Algorithm Program Code

The document describes an experiment to implement the DDA (Digital Differential Analyzer) line drawing algorithm. The program code takes in x1, y1 and x2, y2 coordinates from the user, calculates the slope of the line between the points, and uses the DDA algorithm to incrementally draw the line by putting pixels on the screen over increment steps.

Uploaded by

Ok Nair
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Experiment No:2: AIM: Write A Program To Implement DDA Line Drawing Algorithm Program Code

The document describes an experiment to implement the DDA (Digital Differential Analyzer) line drawing algorithm. The program code takes in x1, y1 and x2, y2 coordinates from the user, calculates the slope of the line between the points, and uses the DDA algorithm to incrementally draw the line by putting pixels on the screen over increment steps.

Uploaded by

Ok Nair
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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