forked from thebishaldeb/ComputerGraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DDA.c
41 lines (39 loc) · 906 Bytes
/
DDA.c
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
41
#include <stdio.h>
#include <graphics.h>
#include <math.h>
void lineDDA(double x1, double y1, double x2, double y2)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
double dx, dy, x, y, del, delx, dely;
int i;
dx = x2 - x1;
dy = y2 - y1;
x = x1;
y = y1;
if (abs(dx) > abs(dy))
del = abs(dx);
else
del = abs(dy);
delx = dx / del;
dely = dy / del;
putpixel(round(x), round(y), RED);
for (i = 0; i < del; i++)
{
x += delx;
y += dely;
int color = i < del / 2 ? 2 : 4;
putpixel(round(x), round(y), color);
}
getch();
closegraph();
}
int main()
{
double x1, y1, x2, y2;
printf("\nEnter x1, y1, x2, y2\n");
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
printf("\nx1 = %lf, y1 = %lf, x2 = %lf, y2 = %lf\n", x1, y1, x2, y2);
lineDDA(x1, y1, x2, y2);
return 0;
}