Bitmap/Bresenham's line algorithm: Difference between revisions

m
→‎Maple: Cleaned up a bit, and changed a few variable names.
m (→‎Maple: Cleaned up a bit, and changed a few variable names.)
Line 669:
 
<lang maple>SegmentBresenham := proc (img, x0, y0, x1, y1)
local deltax, deltay, x, y, ystep, boolsteep, eerr, img2, swap, x02, y02, x12, y12;
x02 := y0; x02, x12, := y1;y02, y12 := x1;y0, y02y1, :=x0, x0x1;
bool steep := abs(x12 - x02) < abs(y12 - y02);
img2 := copy(img);
if boolsteep then
swap := x02; x02, y02 := y02;, y02 := swapx02;
swap := x12; x12, y12 := y12;, y12 := swapx12;
end if;
if x12 < x02 then
swap := x02; x02 := x12; x12 := swap;
swap := y02; y02 := y12; y12 := swap;
end if;
deltax := x12-x02;
deltay := abs(y12-y02);
e := (1/2)*deltax;
y := y02;
if y02 < y12 then
ystep := 1 else ystep := -1; end if;
for x from x02 to x12 do
if bool then
img2[y, x] := 0
else
img2[x, y] := 0;
end if;
eif :=x12 e-deltay;< x02 then
if e < 0 thenx02, x12 := x12, x02;
yy02, y12 := y+ystep;y12, y02;
e := e+deltax;
end if;
deltax := x12 - x02;
end do;
deltay := abs(y12 - y02);
img2;
err := deltax / 2;
y := y02;
if x12y02 < x02y12 then
ystep := 1
else
ystep := 1 else ystep := -1; end if;
end if;
swapfor :=x x02;from x02 :=to x12; x12 := swap;do
if boolsteep then
img2[y, x] := 0
else
img2[x, y] := 0;
end if;
err := err - deltay;
if y02err < y120 then
y := y + ystep;
e err := eerr + deltax;
end if;
end do;
return img2;
end proc:</lang>
 
 
=={{header|MAXScript}}==
Anonymous user