Bitmap/Bresenham's line algorithm: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (→version 2: correct output) |
(→version 1: simplified the program, eliminated the re-calculating of the min and max point values, removed the STYLE from the PRE html tag.) |
||
Line 1,978:
=={{header|REXX}}==
===version 1===
This REXX version has automatic scaling (for displaying the plot).
<lang rexx>/*REXX program plots/draws a line using the Bresenham's line algorithm.*/
@.='·'
if
if
if
border=2 /*border=extra space around plot.*/
minX=
minY=
do x=minX to maxX; @.x.0='─'; end /*draw dash from left──► right.*/
do y=minY to maxY; @.0.y='│'; end /*draw pipe from lowest──►highest*/
@.0.0='┼' /*
call draw_line
/* [↓]
do y=maxY to minY by -1; _= /*display plot one line at a time*/
do x=minX to maxX /*traipse throught the X axis. */
_=_ || @.x.y /*construct a "line" of the plot.*/
end /*x*/ /*(a line is a "row" of points.) */
say _ /*display a "line" of the plot.
end /*y*/ /* [↑] all done ploting the pts.*/
exit /*stick a fork in it, we're done.*/
/*────────────────────────────────DRAW_LINE subroutine──────────────────*/
draw_line: procedure expose @.;
if x<xf then sx=+1
else sx=-1
Line 2,011 ⟶ 2,009:
else sy=-1
err=dx-dy
do forever;
if x=xf & y=yf then leave /*are plot points at the finish? */
if 2*err > -dy
if 2*err <
▲ end /*forever*/
return</lang>
'''output''' when using the default input:
<pre>
·····│··········
·····│··········
·····│·····
·····│····
·····│····
·····│···
·····│···
·····│··
·····│··
·····│·
·····│·
·····
─────┼Θ─────────
·····
·····
····
·····│··········
·····│··········
|