Bitmap/Bresenham's line algorithm: Difference between revisions
Content added Content deleted
m (→version 1: changed indentation for subroutine, split do/end groups, added/changed whitespace and comments, used template for the output section.) |
m (→{{header|REXX}}: changed some comments, used faster assignments, made the drawLine procedure simpler.) |
||
Line 3,327: | Line 3,327: | ||
if data='' then data= "(1,8) (8,16) (16,8) (8,1) (1,8)" /* ◄──── a rhombus.*/ |
if data='' then data= "(1,8) (8,16) (16,8) (8,1) (1,8)" /* ◄──── a rhombus.*/ |
||
data= translate(data, , '()[]{}/,:;') /*elide chaff from the data points. */ |
data= translate(data, , '()[]{}/,:;') /*elide chaff from the data points. */ |
||
@.= '·' /* |
@.= '·' /*use mid─dots chars (plot background).*/ |
||
do points=1 while data\='' /*put the data points into an array (!)*/ |
do points=1 while data\='' /*put the data points into an array (!)*/ |
||
parse var data x y data; !.points=x y /*extract the line segments. */ |
parse var data x y data; !.points=x y /*extract the line segments. */ |
||
Line 3,352: | Line 3,352: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
drawLine: procedure expose @.; |
drawLine: procedure expose @.; parse arg x y,xf yf; parse value '-1 -1' with sx sy |
||
dx= abs(xf-x); if x<xf then sx= |
dx= abs(xf-x); if x<xf then sx= 1 /*obtain X range, determine the slope*/ |
||
dy= abs(yf-y); if y<yf then sy= 1 /* " Y " " " " */ |
|||
dy= abs(yf-y); if y<yf then sy= +1 /*obtain Y range, determine the slope*/ |
|||
⚫ | |||
err= dx - dy /*calculate error between adjustments. */ |
err= dx - dy /*calculate error between adjustments. */ |
||
⚫ | |||
do forever; @.x.y= |
do forever; @.x.y= 'Θ' /*plot the points until it's complete. */ |
||
if x=xf & y=yf then return /*are the plot points at the finish? */ |
if x=xf & y=yf then return /*are the plot points at the finish? */ |
||
err2= err + err /*calculate double the error |
err2= err + err /*calculate double the error value. */ |
||
if err2 > -dy then do; err= err - dy; x= x + sx; end |
if err2 > -dy then do; err= err - dy; x= x + sx; end |
||
if err2 < dx then do; err= err + dx; y= y + sy; end |
if err2 < dx then do; err= err + dx; y= y + sy; end |
||
Line 3,389: | Line 3,387: | ||
</pre> |
</pre> |
||
===version 2=== |
=== version 2 === |
||
<lang rexx>/* REXX *************************************************************** |
<lang rexx>/* REXX *************************************************************** |
||
* 21.05.2014 Walter Pachl |
* 21.05.2014 Walter Pachl |