-
Notifications
You must be signed in to change notification settings - Fork 0
/
BRESENHAM.C
82 lines (82 loc) · 1.3 KB
/
BRESENHAM.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int x,a, y, x1, y1, x2, y2, Dx, Dy, twoDx, twoDy, twoDyDx, p, end;
int gd=DETECT, gm;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
for(a=1;a<5;a++){
if(a==1){
x1=100;
y1=100;
x2=150;
y2=100;
}
if(a==2){
x1=100;
y1=100;
x2=100;
y2=150;
}
if(a==3){
x1=100;
y1=150;
x2=150;
y2=150;
}
if(a==4){
x1=150;
y1=150;
x2=150;
y2=100;
}
if(x1==x2){
x=x1;
y=y1;
while(y!=y2){
if((y2-y1)>0)
++y;
else
--y;
putpixel(x,y,WHITE);
}
if(y1>=y2){
x=x2;
y=y2;
end=y2;
}
}
if(x1<x2){
x=x1;
y=y1;
end=x2;
}
else{
x=x2;
y=y2;
end=x1;
}
putpixel(x,y,WHITE);
Dx=abs(x1-x2);
Dy=abs(y1-y2);
twoDy=2*Dy;
twoDyDx=2*(Dy-Dx);
p=2*Dy-Dx;
while(x<end){
if(p<0){
x++;
p+=twoDy;
}
else{
x++;
y++;
p=twoDyDx;
}
putpixel(x,y,WHITE);
}
}
getch();
closegraph();
}