0% found this document useful (0 votes)
4 views1 page

DDA Code

The document presents a C program implementing the DDA (Digital Differential Analyzer) line drawing algorithm. It prompts the user to input the coordinates of two points and calculates the steps required to draw a line between them using pixel plotting. The program utilizes graphics library functions to display the line on the screen.

Uploaded by

nv237977
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

DDA Code

The document presents a C program implementing the DDA (Digital Differential Analyzer) line drawing algorithm. It prompts the user to input the coordinates of two points and calculates the steps required to draw a line between them using pixel plotting. The program utilizes graphics library functions to display the line on the screen.

Uploaded by

nv237977
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DDA Line Drawing Algorithm (C Program)

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <stdlib.h>

float x, y, x1, y1, x2, y2, dx, dy, step, xinc, yinc;

void main()
{
int gd = DETECT, gm, i;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");

printf("Enter the coordinate of x1 and y1: ");


scanf("%f %f", &x1, &y1);

printf("Enter the coordinate of x2 and y2: ");


scanf("%f %f", &x2, &y2);

dx = x2 - x1;
dy = y2 - y1;

if (abs(dx) > abs(dy))


step = abs(dx);
else
step = abs(dy);

xinc = dx / step;
yinc = dy / step;

x = x1;
y = y1;

putpixel(x, y, WHITE);

for (i = 0; i < step; i++)


{
x = x + xinc;
y = y + yinc;
putpixel(x, y, WHITE);
}

getch();
closegraph();
}

You might also like