-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBresenham Normal.c
More file actions
57 lines (48 loc) · 1.21 KB
/
Bresenham Normal.c
File metadata and controls
57 lines (48 loc) · 1.21 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Normal Bresenham Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd = DETECT, gm, x1, y1, x2, y2, len, i, dx, dy, k = 0;
int x, y, xinc, yinc, p, temp, s1, s2;
initgraph(&gd, &gm, "..//bgi");
printf("Enter the co-ordinates of the first point: \n");
scanf("%d%d", &x1, &y1);
printf("Enter the co-ordinates of the second point: \n");
scanf("%d%d", &x2, &y2);
dx = abs(x2 - x1);
dy = abs(y2 - y1);
len = abs(dx) >= abs(dy) ? abs(dx) : abs(dy);
p = 2 * dy - dx;
x = x1;
y = y1;
if(dy >= dx) {
temp = dx;
dx = dy;
dy = temp;
k = 1;
}
s1 = (x2 - x1) > 0 ? 1 : -1;
s2 = (y2 - y1) > 0 ? 1 : -1;
for(i = 0; i < len; i++) {
if(p >= 0) {
putpixel(x, y, WHITE);
x += s1;
y += s2;
p += 2 * dy - 2 * dx;
} else {
if(k == 1) {
putpixel(x, y, WHITE);
y += s2;
p += 2 * dy;
} else {
putpixel(x, y, WHITE);
x += s1;
p += 2 * dy;
}
}
}
getch();
closegraph();
}