Xiaolin Wu's line algorithm: Difference between revisions
Content added Content deleted
(Added Julia language) |
m (→{{header|REXX}}: added/changed comments and whitespace.) |
||
Line 1,983:
<br>Also, it takes in account (that can easily be overlooked) of the note after the description of the algorithm:
<br>'''Note''': If at the beginning of the routine abs(''dx'') < abs(''dy'') is true, then all plotting should be done with '''x''' and '''y''' reversed.
<lang rexx>/*REXX program plots/draws (ASCII) a line using the Xiaolin Wu line algorithm.
background= '·' /*background character: a middle-dot. */
image.= background /*fill the array with middle-dots. */
Line 2,002:
call drawLine xi, yi, xf, yf /*invoke subroutine and graph the line.*/
border=2 /*allow additional space (plot border).*/
minX=minX - border * 2;
minY=minY - border ;
do y=maxY to minY by -1;
do x=minX to maxX;
say
end /*y*/ /*graph is cropped by the MINs and MAXs*/
exit /*stick a fork in it, we're all done. */
Line 2,027:
call plotXY xpx12, ypx12+1, brite( fpart(yend*xgap)), switchXY
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
brite: return substr(background || plotC, 1 + round( abs( arg(1) ) * length(plotC)), 1)
floor: parse arg
fpart: parse arg
round: return format(arg(1), , word(arg(2) 0, 1) )
/*──────────────────────────────────────────────────────────────────────────────────────*/
plotXY: parse arg xx,yy,bc,switchYX; if switchYX then parse arg yy,xx
image.xx.yy=bc; minX=min(minX, xx);
minY=min(minY, yy);
{{out|output|text= when using the default inputs:}}
<pre>
|