Anonymous user
Bitmap/Bresenham's line algorithm: Difference between revisions
m
→version 1: changed indentation for subroutine, split do/end groups, added/changed whitespace and comments, used template for the output section.
m (correct potential edge case failure) |
m (→version 1: changed indentation for subroutine, split do/end groups, added/changed whitespace and comments, used template for the output section.) |
||
Line 3,320:
=={{header|REXX}}==
=== version 1 ===
This REXX version has automatic scaling (for displaying the plot), includes a border, accepts lines segments from the
<br>command line, displays a (background) plot field, and it also handles multiple line segments.
Line 3,326:
parse arg data /*obtain optional arguments from the CL*/
if data='' then data= "(1,8) (8,16) (16,8) (8,1) (1,8)" /* ◄──── a rhombus.*/
data= translate(data, , '()[]{}/,:;')
@.= '·'
do points=1 while data\=''
parse var data x y data;
if points==1 then do; minX= x; maxX= x; minY= y; maxY= y
end
minX= min(minX,x); maxX= max(maxX,x); minY= min(minY,y); maxY= max(maxY,y)
end /*points*/ /* [↑] data points pairs in array !. */▼
minY= minY - border ; maxY=
do
@.0.0= '┼'
call drawLine !._, !.seg /*draw (plot) a line segment. */
/* [↓] display the plot to terminal. */
do y=maxY to minY by -1; _=
do x=minX to maxX;
end /*x*/
say _
end /*y*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
dx= abs(xf-x); if x<xf then sx= +1
dy= abs(yf-y); if y<yf then sy= +1
if err2
if err2 < dx then do; err= err + dx; y= y + sy; end
end /*forever*/</lang>
<pre>
···│····················
|