Bitmap/Bresenham's line algorithm: Difference between revisions
→version 2: Rexx version 2 corrected
(→version 1: redid the whole program, the program that it was previously based on was faulty.) |
Walterpachl (talk | contribs) (→version 2: Rexx version 2 corrected) |
||
Line 2,034:
===version 2===
<lang>/* REXX ***************************************************************
*
* Implementing the pseudo code of
* http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
* under 'Simplification'
**********************************************************************/
grid.='.'
Do i=-2 To 7; grid.i.0='-'
Do j=-4 To 11; grid.0.j='|'; End
grid.0.0=
Call
Do j=11 To -4 By -1
ol=
Do i=-2 To 7
ol=ol||grid.i.j
End
Say ol
End
Say ' 2101234567'
Exit
line: Procedure Expose grid.
Parse Arg x0,
if x0 < x1 then sx = 1
else sx = -1
if y0 < y1 then sy = 1
else sy = -1
err = dx-dy
grid.x.y='X';▼
Do Forever
if x0 = x1 & y0 = y1 Then Leave
e2 =
if e2 > -dy then do
err = err - dy
x0 = x0 + sx
end
if e2 < dx then do
err = err + dx
y0 = y0 + sy
end
end
Return</lang>
'''output'''
<pre>11 ..|.......
10 ..|.....X.
9 ..|....
8 ..|....X..
7 ..|...
6 ..|...X...
5 ..|..
4 ..|..X....
3 ..|.X.....
2 ..|.
1 ..|X......
0 --
-1 ..X.......
-2 ..
-3 .X|.......
-4 ..|.......
|