Bitmap/Bresenham's line algorithm: Difference between revisions

m
→‎{{header|REXX}}: changed some comments, used faster assignments, made the drawLine procedure simpler.
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:
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. */
@.= '·' /*filluse themid─dots arraychars with(plot middle─dots charsbackground).*/
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. */
Line 3,352:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
drawLine: procedure expose @.; parse arg x y,xf yf; parse value '-1 -1' with plotChar=sx 'Θ'sy
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 else sx= -1 /* " " " negative slope. " */
dy= abs(yf-y); if y<yf then sy= +1 /*obtain Y range, determine the slope*/
else sy= -1 /* negative slope. */
err= dx - dy /*calculate error between adjustments. */
else sy= -1 /* /*Θ is the plot character for negative slopepoints. */
 
do forever; @.x.y= plotChar 'Θ' /*plot the points until it's complete. */
if x=xf & y=yf then return /*are the plot points at the finish? */
err2= err + err /*calculate double the error numbervalue. */
if err2 > -dy then do; err= err - dy; x= x + sx; end
if err2 < dx then do; err= err + dx; y= y + sy; end
Line 3,389 ⟶ 3,387:
</pre>
 
=== version 2 ===
<lang rexx>/* REXX ***************************************************************
* 21.05.2014 Walter Pachl