-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bresenham.adb
202 lines (188 loc) · 6.58 KB
/
Bresenham.adb
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
With ada.text_io, ada.integer_text_io, Tools, Rand;
Use ada.text_io, ada.integer_text_io, Tools, Rand;
Package body Bresenham is
Procedure BresenhamCircle (
Xcentre,
Ycentre,
Rayon : integer;
MyPix : in out Pixel;
Full : boolean;
MyImg: T_Image)
is
x : integer := 0;
y : integer := Rayon;
m : integer := 5 - 4*y;
begin
while x <= y loop
MyImg (Ycentre + y, Xcentre + x) := MyPix;
MyImg (Ycentre + x, Xcentre + y) := MyPix;
MyImg (Ycentre + y, Xcentre - x) := MyPix;
MyImg (Ycentre + x, Xcentre - y) := MyPix;
MyImg (Ycentre - y, Xcentre + x) := MyPix;
MyImg (Ycentre - x, Xcentre + y) := MyPix;
MyImg (Ycentre - y, Xcentre - x) := MyPix;
MyImg (Ycentre - x, Xcentre - y) := MyPix;
if m > 0 then
y := y - 1;
m := m - 8 * y;
end if;
x := x + 1;
m := m + 8 * x + 4 ;
end loop;
if Full and then Rayon /= 0 then
MyPix := (Rand.flt, Rand.flt, Rand.flt);
BresenhamCircle (Xcentre, Ycentre, Rayon-1, MyPix, true, MyImg);
end if;
end BresenhamCircle;
Procedure AndresCircle (
Xcentre,
Ycentre,
Rayon : integer;
MyPix : in out Pixel;
Full : boolean;
MyImg: T_Image)
is
x : integer := 0;
y : integer := Rayon;
d : integer := Rayon -1;
begin
x := 0;
y := Rayon;
d := Rayon - 1;
while y >=x loop
MyImg (Xcentre + x , Ycentre + y ) := MyPix;
MyImg (Xcentre + y , Ycentre + x ) := MyPix;
MyImg (Xcentre - x , Ycentre + y ) := MyPix;
MyImg (Xcentre - y , Ycentre + x ) := MyPix;
MyImg (Xcentre + x , Ycentre - y ) := MyPix;
MyImg (Xcentre + y , Ycentre - x ) := MyPix;
MyImg (Xcentre - x , Ycentre - y ) := MyPix;
MyImg (Xcentre - y , Ycentre - x ) := MyPix;
if d >= 2 * x then
d := d - 2*x - 1;
x := x+1;
elsif d < 2 * (Rayon-y) then
d := d + 2*y - 1;
y := y-1;
else
d := d + 2 * (y-x-1);
y := y-1;
x := x+1;
end if;
end loop;
if Full and then Rayon /= 0 then
MyPix := (Rand.flt, Rand.flt, Rand.flt);
AndresCircle (Xcentre, Ycentre, Rayon-1, MyPix, true, MyImg);
end if;
end AndresCircle;
Procedure traceLine (
xa, ya ,
xb, yb : integer;
MyPix : Pixel;
MyImg : T_Image)
is
x0 : integer := xa;
y0 : integer := ya;
x1 : integer := xb;
y1 : integer := yb;
x, y ,
dx,dy,dp,
deltaE ,
deltaNE : integer;
Procedure Swap is new Tools.Swap (integer);
begin
if y1 < y0 then
Swap (x0, x1);
Swap (y0, y1);
end if;
x := x0;
y := y0;
if x1 >= x0 then
dx:= x1 - x0;
dy:= y1 - y0;
-----------------------------------------------
if dx >= dy then
Put_line ("1a");
dp := 2*dy-dx;
deltaE := 2*dy;
deltaNE:= 2*(dy-dx);
while x <= x1 loop
if dp <= 0 then
MyImg (y,x) := MyPix;
dp := dp + deltaE;
x := x +1;
else
MyImg (y,x) := MyPix;
dp := dp + deltaNE;
x := x +1;
y := y +1;
end if;
Put (x); Put (y); new_line;
end loop;
-----------------------------------------------
elsif dx < dy then
Put_line ("1b");
dp := 2*dx-dy;
deltaE := 2*dx;
deltaNE:= 2*(dx-dy);
while y <= y1 loop
if dp <= 0 then
MyImg (y,x) := MyPix;
dp := dp + deltaE;
y:= y +1;
else
MyImg (y,x) := MyPix;
dp := dp + deltaNE;
x := x +1;
y := y +1;
end if;
Put (x); Put (y); new_line;
end loop;
end if;
-----------------------------------------------
ELSIF x1 < x0 then
dx:= x0 - x1;
dy:= y1 - y0;
-----------------------------------------------
if dx >= dy then
Put_line ("2a");
dp := 2*dy-dx;
deltaE := 2*dy;
deltaNE:= 2*(dy-dx);
while x >= x1 loop
if dp <= 0 then
MyImg (y,x) := MyPix;
dp := dp + deltaE;
x := x -1;
else
MyImg (y,x) := MyPix;
dp := dp + deltaNE;
x := x -1;
y := y +1;
end if;
Put (x); Put (y); new_line;
end loop;
-----------------------------------------------
elsif dx < dy then
Put_line ("2b");
dp := 2*dx-dy;
deltaE := 2*dx;
deltaNE:= 2*(dx-dy);
while y <= y1 loop
if dp <= 0 then
MyImg (y,x) := MyPix;
dp := dp + deltaE;
y := y +1;
else
MyImg (y,x) := MyPix;
dp := dp + deltaNE;
x := x -1;
y := y +1;
end if;
Put (x); Put (y); new_line;
end loop;
end if;
-----------------------------------------------
end if;
end traceLine;
end Bresenham;