Bitmap/Midpoint circle algorithm: Difference between revisions

→‎{{header|REXX}}: added/changed whitespace and comments, simplified the subroutines.
(Added Batch File...)
(→‎{{header|REXX}}: added/changed whitespace and comments, simplified the subroutines.)
Line 1,471:
 
=={{header|REXX}}==
(BecauseProgramming note:   because of character output to a terminal screen, a circle appears to be elongated in the vertical direction because characters are "taller" than they're "wide".
<br>vertical direction because characters are "taller" than they're "wide", so this REXX version attempts to maintain
<lang rexx>/*REXX pgm plots 3 circles using midpoint/Bresenham's circle algorithm. */
<br>a good aspect ratio.
@. = '·' /*fill the array with middle-dots*/
<lang rexx>/*REXX pgmprogram plots 3three circles using midpoint/Bresenham's circle algorithm. */
minX=0; maxX=0; minY=0; maxY=0 /*initialize minimums & maximums.*/
call@. = '·' drawCircle 0, 0, 8, '#' /*plotfill 1stthe circlearray with poundmiddle─dots char.*/
minX=0; maxX=0; minY=0; maxY=0 /*initialize the minimums &and maximums.*/
call drawCircle 0, 0, 11, '$' /* " 2nd " " dollar " */
call drawCircle 0, 0, 19 8, '@#' /*plot 1st "circle with 3rdpound " " commercharacter. at*/
border=2call drawCircle 0, 0, 11, '$' /* " 2nd " " dollar /*BORDER: " shows N extra grid pts*/
call drawCircle 0, 0, 1119, '$@' /* " 2nd3rd " " dollarcommercial at. " */
minX=minX-border*2; maxX=maxX+border*2 /*adjust min&max X to show border*/
minY=minY-border=2 ; maxY=maxY+border /* " " " Y " " " /*BORDER: shows N extra grid points.*/
minX=minX-border*2; maxX=maxX+border*2 /*adjust min& and max X to show border*/
if @.0.0==@. then @.0.0='┼' /*maybe define plot's axis origin*/
minY=minY-border ; maxY=maxY+border /* " " " " Y " " /* [↓] define horizontal grid." */
do gx=minX to maxX; if @.gx0.0==@. then @.gx0.0=''; end /*gxmaybe define the plot's axis origin. */
@. = '·' /*filldefine the arrayplot's horizontal withgrid──┐ middle-dots*/
do gy=minY to maxY; if @.0.gy==@. then @.0.gy='│'; end /*gy*/
do h=minX to maxX; if @.h.0==@. then @.h.0='─'; end /* ◄───────────┘ */
/* [↑] define the vertical grid.*/
do v=minY doto y=maxY; byif -1@.0.v==@. tothen minY@.0.v='│'; aRow=end /* [↓] draw grid/* from◄──────────┐ top to bot.*/
do x=minX to maxX /* [↓] " " " left──►right /*define the plot's vertical grid───┘ */
do y=maxY by -1 to minY; aRow=aRow ||/* @.x.y[↓] draw grid from /*build atop grid row, char by──► charbottom.*/
enddo x=minX /*x*/to maxX /* [↓] " " /* [↑] a" grid rowleft should──► beright. done*/
say aRow aRow=aRow || @.x.y /*build a grid row, one char at a /*display signal row of the gridtime.*/
end /*x*/ /* [↑] definea thegrid verticalrow gridshould be finished. */
say aRow /*display a single row of the grid. */
end /*y*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
/*───────────────────────────────────DRAWCIRCLE subroutine──────────────*/
drawCircle: procedure expose @. minX maxX minY maxY /* [↓] Y is defined as R*/
parse arg xx,yy,r 1 y,plotChar; f=1-r; fx=1; fy=-2*r; /*get the X,Y y=rcoordinates*/
 
do x=0 while x<y /*▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒*/
do x=0 while x<y /*════════════════════════════════════════*/
if f>=0 then do; y=y-1; fy=fy+2; f=f+fy; end /*▒*/
fx=fx+2; f=f+fx /*▒*/
call plotPoint xx+x, yy+y, plotChar /*▒*/
call plotPoint xx+y, yy+x, plotChar /*▒*/
call plotPoint xx+y, yy-x, plotChar /*▒*/
call plotPoint xx+x, yy-y, plotChar /*▒*/
call plotPoint xx-y, yy+x, plotChar /*▒*/
call plotPoint xx-x, yy+y, plotChar /*▒*/
call plotPoint xx-x, yy-y, plotChar /*▒*/
call plotPoint xx-y, yy-x, plotChar /*▒*/
end /*x*/ /* [↑] place plot points ══► plot.▒▒▒▒▒▒▒▒▒▒▒▒▒*/
return
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────PLOTPOINT subroutine────────────────*/
plotPoint: procedureparse exposearg c,r; @.c.r=plotChar minX maxX minY/*assign maxYa character to be plotted.*/
parse arg xx,yy,@.xx.yy; minX=min(minX,xxc); maxX=max(maxX,xxc) /*find the minimum and maximum X. */
minY=min(minY,r); maxY=max(maxY,r) /* " " " " " minY=min(minY,yy); Y. maxY=max(maxY,yy)*/
return</lang>
{{out}}