Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,43 @@
|
|||
/*REXX program plots/draws line(s) using the Bresenham's line algorithm.*/
|
||||
@.='·' /*fill the array with middle─dots*/
|
||||
parse arg data /*allow data point specifications*/
|
||||
if data='' then data= '(1,8) (8,16) (16,8) (8,1) (1,8)' /*rhombus*/
|
||||
data=translate(data,,'()[]{}/,:;') /*elide chaff from data points. */
|
||||
/* [↓] data pt pairs ──► !.array.*/
|
||||
do points=1 while data\='' /*put data points into an array. */
|
||||
parse var data x y data; !.points=x y /*extract line segments.*/
|
||||
if points==1 then do; minX=x; maxX=x; minY=y; maxY=y; end /*1st case*/
|
||||
minX=min(minX,x); maxX=max(maxX,x); minY=min(minY,y); maxY=max(maxY,y)
|
||||
end /*points*/ /* [↑] data points pairs in !. */
|
||||
|
||||
border=2 /*border=extra space around plot.*/
|
||||
minX=minX-border*2; maxX=maxX+border*2 /*min,max X for the plot display.*/
|
||||
minY=minY-border ; maxY=maxY+border /* " " Y " " " " */
|
||||
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*/
|
||||
@.0.0='┼' /*define the plot's axis point. */
|
||||
do seg=2 to points-1; _=seg-1 /*obtain the X,Y line coördinates*/
|
||||
call draw_line !._, !.seg /*draw (plot) a line segment. */
|
||||
end /*seg*/ /* [↑] drawing the line segments*/
|
||||
/* [↓] display the plot to term.*/
|
||||
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 plot.*/
|
||||
end /*x*/ /*(a line is a "row" of points.) */
|
||||
say _ /*display a "line" of the plot. */
|
||||
end /*y*/ /* [↑] all done ploting the pts.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*────────────────────────────────DRAW_LINE subroutine──────────────────*/
|
||||
draw_line: procedure expose @.; parse arg x y,xf yf; plotChar='Θ'
|
||||
dx=abs(xf-x); if x<xf then sx=+1 /*obtain X range, determine slope*/
|
||||
else sx=-1
|
||||
dy=abs(yf-y); if y<yf then sy=+1 /*obtain Y range, determine slope*/
|
||||
else sy=-1
|
||||
err=dx-dy /*calc error between adjustments.*/
|
||||
do forever; @.x.y=plotChar /*plot the points until complete.*/
|
||||
if x=xf & y=yf then leave /*are plot points at the finish? */
|
||||
err2=err+err /*this is faster than err*2. */
|
||||
if err2 > -dy then do; err=err-dy; x=x+sx; end
|
||||
if err2 < dx then do; err=err+dx; y=y+sy; end
|
||||
end /*forever*/
|
||||
return
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/* REXX ***************************************************************
|
||||
* 21.05.2014 Walter Pachl
|
||||
* Implementing the pseudo code of
|
||||
* http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
||||
* under 'Simplification'
|
||||
**********************************************************************/
|
||||
grid.='.'
|
||||
Do i=-2 To 7; grid.i.0='-'; End
|
||||
Do j=-4 To 11; grid.0.j='|'; End
|
||||
grid.0.0='+'
|
||||
Call line -1,-3,6,10
|
||||
Do j=11 To -4 By -1
|
||||
ol=format(j,2)' '
|
||||
Do i=-2 To 7
|
||||
ol=ol||grid.i.j
|
||||
End
|
||||
Say ol
|
||||
End
|
||||
Say ' 2101234567'
|
||||
Exit
|
||||
line: Procedure Expose grid.
|
||||
Parse Arg x0, y0, x1, y1
|
||||
dx = abs(x1-x0)
|
||||
dy = abs(y1-y0)
|
||||
if x0 < x1 then sx = 1
|
||||
else sx = -1
|
||||
if y0 < y1 then sy = 1
|
||||
else sy = -1
|
||||
err = dx-dy
|
||||
|
||||
Do Forever
|
||||
grid.x0.y0='X'
|
||||
if x0 = x1 & y0 = y1 Then Leave
|
||||
e2 = 2*err
|
||||
if e2 > -dy then do
|
||||
err = err - dy
|
||||
x0 = x0 + sx
|
||||
end
|
||||
if e2 < dx then do
|
||||
err = err + dx
|
||||
y0 = y0 + sy
|
||||
end
|
||||
end
|
||||
Return
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/*REXX program plots/draws a line using the Bresenham's line algorithm. */
|
||||
|
||||
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*/
|
||||
do j=-EoE to +EoE /*draw grid from lowest──>highest*/
|
||||
image.j.0 = '─' /*draw the horizontal axis. */
|
||||
image.0.j = '│' /* " " verical " */
|
||||
end /*j*/
|
||||
image.0.0='┼' /*"draw" the axis origin. */
|
||||
parse arg xi yi xf yf . /*allow specifying line-end pts. */
|
||||
if xi=='' | xi==',' then xi = -1 /*if not specified, use default. */
|
||||
if yi=='' | yi==',' then yi = -3 /* " " " " " */
|
||||
if xf=='' | xf==',' then xf = 6 /* " " " " " */
|
||||
if yf=='' | yf==',' then yf = 10 /* " " " " " */
|
||||
call draw_line xi, yi, xf, yf /*call subroutine and draw line. */
|
||||
call findMaxXY
|
||||
do y=maxY by -1 to minY; aRow=
|
||||
do x=minX to maxX
|
||||
aRow=aRow || image.x.y
|
||||
end /*x*/
|
||||
say aRow
|
||||
end /*y*/
|
||||
exit
|
||||
/*────────────────────────────────DRAW_LINE subroutine──────────────────*/
|
||||
draw_line: procedure expose image. plotC; error=0
|
||||
parse arg xi 1 x0, yi 1 y0 1 y, xf 1 x1, yf 1 y1
|
||||
steep= abs(y1-y0) > abs(x1-x0)
|
||||
if steep then parse value x0 y0 x1 y1 with y0 x0 y1 x1
|
||||
if x0>x1 then parse value x0 x1 y0 y1 with x1 x0 y1 y0
|
||||
|
||||
if y0<y1 then yInc = 1
|
||||
else yInc = -1
|
||||
deltaE=abs(y1-y0) / (x1-x0)
|
||||
|
||||
do x=x0 to x1
|
||||
if steep then image.y.x=plotC
|
||||
else image.x.y=plotC
|
||||
error=error+deltaE
|
||||
if error>=.5 then do; y=y+yInc; error=error-1; end
|
||||
end
|
||||
return
|
||||
/*────────────────────────────────FINDMAXXY subroutine──────────────────*/
|
||||
findMaxXY: extra=3 /*don't just show cropped plot. */
|
||||
do minX=-EoE to +EoE /*find min X in the plot field. */
|
||||
do y=-EoE to +EoE; if .isP(image.minX.y) then leave minX; end /*y*/
|
||||
end /*minX*/
|
||||
|
||||
do maxX=+EoE to -EoE by -1 /*find max X in the plot field. */
|
||||
do y=-EoE to +EoE; if .isP(image.maxX.y) then leave maxX; end /*y*/
|
||||
end /*maxX*/
|
||||
|
||||
do minY=-EoE to +EoE /*find min Y in the plot field. */
|
||||
do x=-EoE to +EoE; if .isP(image.x.minY) then leave minY; end /*x*/
|
||||
end /*minY*/
|
||||
|
||||
do maxY=+EoE to -EoE by -1 /*find max Y in the plot field. */
|
||||
do x=-EoE to +EoE; if .isP(image.X.maxy) then leave maxY; end /*x*/
|
||||
end /*maxY*/
|
||||
|
||||
minX=minX-extra*2; minY=minY-extra /*like showbiz, show a little more*/
|
||||
maxX=maxX+extra*2; maxY=maxY+extra /* " " " " " " */
|
||||
return /*go ye forth and show ye plot. */
|
||||
.isP: return pos(arg(1),plotC)\==0
|
||||
Loading…
Add table
Add a link
Reference in a new issue