Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,23 @@
|
|||
Local $var = drawBresenhamLine(2, 3, 2, 6)
|
||||
|
||||
Func drawBresenhamLine($iX0, $iY0, $iX1, $iY1)
|
||||
Local $iDx = Abs($iX1 - $iX0)
|
||||
Local $iSx = $iX0 < $iX1 ? 1 : -1
|
||||
Local $iDy = Abs($iY1 - $iY0)
|
||||
Local $iSy = $iY0 < $iY1 ? 1 : -1
|
||||
Local $iErr = ($iDx > $iDy ? $iDx : -$iDy) / 2, $e2
|
||||
|
||||
While $iX0 <= $iX1
|
||||
ConsoleWrite("plot( $x=" & $iX0 & ", $y=" & $iY0 & " )" & @LF)
|
||||
If ($iX0 = $iX1) And ($iY0 = $iY1) Then Return
|
||||
$e2 = $iErr
|
||||
If ($e2 > -$iDx) Then
|
||||
$iErr -= $iDy
|
||||
$iX0 += $iSx
|
||||
EndIf
|
||||
If ($e2 < $iDy) Then
|
||||
$iErr += $iDx
|
||||
$iY0 += $iSy
|
||||
EndIf
|
||||
WEnd
|
||||
EndFunc ;==>drawBresenhamLine
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
function line(img, x0::Int, y0::Int, x1::Int, y1::Int, col)
|
||||
dx = int(abs(x1-x0))
|
||||
dy = int(abs(y1-y0))
|
||||
|
||||
sx = x0<x1 ? 1 : -1
|
||||
sy = y0<y1 ? 1 : -1;
|
||||
|
||||
err = (dx>dy ? dx : -dy)/2
|
||||
|
||||
while true
|
||||
@inbounds img[x0,y0]=col
|
||||
if (x0==x1 && y0==y1); break; end
|
||||
e2 = err;
|
||||
if e2 > -dx
|
||||
err -= dy
|
||||
x0 += sx
|
||||
end
|
||||
if e2 < dy
|
||||
err += dx
|
||||
y0 += sy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,43 +1,42 @@
|
|||
/*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 !. */
|
||||
/*REXX program plots/draws line segments using the Bresenham's line algorithm.*/
|
||||
@.='·' /*fill the array with middle─dots chars*/
|
||||
parse arg data /*allow the data point specifications. */
|
||||
if data='' then data= '(1,8) (8,16) (16,8) (8,1) (1,8)' /*◄────rhombus.*/
|
||||
data=translate(data,,'()[]{}/,:;') /*elide chaff from the data points. */
|
||||
/* [↓] data point pairs ───► !.array. */
|
||||
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. */
|
||||
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 array !. */
|
||||
|
||||
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*/
|
||||
border=2 /*border: is extra space around plot. */
|
||||
minX=minX-border*2; maxX=maxX+border*2 /*min and max X for the plot display.*/
|
||||
minY=minY-border ; maxY=maxY+border /* " " " Y " " " " */
|
||||
do x=minX to maxX; @.x.0='─'; end /*draw a dash from left ───► right.*/
|
||||
do y=minY to maxY; @.0.y='│'; end /*draw a pipe from lowest ───► highest*/
|
||||
@.0.0='┼' /*define the plot's origin axis point. */
|
||||
do seg=2 to points-1; _=seg-1 /*obtain the X and Y line coördinates*/
|
||||
call draw_line !._, !.seg /*draw (plot) a line segment. */
|
||||
end /*seg*/ /* [↑] drawing the line segments. */
|
||||
/* [↓] display the plot to terminal. */
|
||||
do y=maxY to minY by -1; _= /*display the plot one line at a time. */
|
||||
do x=minX to maxX /*build line by examining the X axis.*/
|
||||
_=_ || @.x.y /*construct/build a line of the plot. */
|
||||
end /*x*/ /* (a line is a "row" of points.) */
|
||||
say _ /*display a line of the plot──►terminal*/
|
||||
end /*y*/ /* [↑] all done plotting the points. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
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 the slope*/
|
||||
else sx=-1
|
||||
dy=abs(yf-y); if y<yf then sy=+1 /*obtain Y range, determine slope*/
|
||||
dy=abs(yf-y); if y<yf then sy=+1 /*obtain Y range, determine the 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
|
||||
err=dx-dy /*calculate error between adjustments. */
|
||||
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 /*addition 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
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ object BitmapOps {
|
|||
if (e2<dy) {err+=dx; y+=sy}
|
||||
res;
|
||||
}
|
||||
def hasNext=(x<=x1 && y<=y1)
|
||||
def hasNext = (sx*x <= sx*x1 && sy*y <= sy*y1)
|
||||
}
|
||||
|
||||
for((x,y) <- it)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue