Anonymous user
Bitmap/Bresenham's line algorithm: Difference between revisions
→version 1: redid the whole program, the program that it was previously based on was faulty.
m (→version 1: changed some comments and indentation, added whitespace.) |
(→version 1: redid the whole program, the program that it was previously based on was faulty.) |
||
Line 1,964:
=={{header|REXX}}==
===version 1===
EoE = 1000 /*EOE = End Of Earth, er, plot. */▼
▲image. = 'fa'x /*fill the array with middle-dots*/
plotC = 'fe'x /*character used for plotting pts*/
parse arg x0 y0 x1 y1 .
if x0=='' | x0==',' then
if y0=='' | y0==',' then y0 = -3 /* "
if x1=='' | x1==',' then x1 = 6 /* " " " " "
minX=min(x0,x1); minY=min(y0,y1) /*find the min and max X value.*/
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*/
call draw_line x0, y0, x1, y1 /*call subroutine and draw line. */
▲minX=minX-border*2; maxX=maxX+border*2
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
end /*x*/ /*(a line is a "row" of points.)
say _ /*display a line of the plot.
end /*y*/ /* [↑] all done ploting the
exit /*stick a fork in it, we're done.*/
/*────────────────────────────────DRAW_LINE subroutine──────────────────*/
draw_line: procedure expose
parse arg
if x<xf then sx=+1
else sx=-1
if y<yf then sy=+1
else sy=-1
err=dx-dy
if y0<y1 then yInc = 1▼
do
call plotXY x,y,plotC
if e2< dx then do; err=err+dx; y=y+sy;
end
return
/*────────────────────────────────PLOTXY subroutine─────────────────────*/
plotXY: procedure expose
minY=min(minY,yy); maxY=max(maxY,yy)
return</lang>
'''output''' when using the default input
<pre style="overflow:scroll">
·····│·
·····│··
·····│·
·····│··
·····│·
·····│··
·····│·
·····
·····
─────┼■─────────
·····
····
···
</pre>
|