-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdda_line.c
More file actions
40 lines (36 loc) · 808 Bytes
/
dda_line.c
File metadata and controls
40 lines (36 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <math.h>
#include <graphics.h>
#include <conio.h>
void main()
{
int gd = DETECT, gm;
int x1, x2, y1, y2, dx, dy, step, xinc, yinc, i;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
printf("Enter the starting coordinates (x1, y1): ");
scanf("%d%d", &x1, &y1);
printf("Enter the ending coordinates (x2, y2): ");
scanf("%d%d", &x2, &y2);
// calculating dx and dy
dx = x2 - x1;
dy = y2 - y1;
if (abx(dx) > abs(dy))
{
step = abs(dx);
}
else
{
step = abs(dy);
}
// now calculating the increment values
xinc = dx / step;
yinc = dy / step;
for (i = 1; i <= step; i++)
{
putpixel(x1, y1, WHITE);
x1 = x1 + xinc;
y1 = y1 + yinc;
}
getch();
closegraph();
}