Anonymous user
Bitmap/Midpoint circle algorithm: Difference between revisions
→{{header|REXX}}: added/changed whitespace and comments, simplified the subroutines.
Simple9371 (talk | contribs) (Added Batch File...) |
(→{{header|REXX}}: added/changed whitespace and comments, simplified the subroutines.) |
||
Line 1,471:
=={{header|REXX}}==
<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*/▼
minX=0; maxX=0; minY=0; maxY=0 /*initialize minimums & maximums.*/▼
call drawCircle 0, 0, 11, '$' /* " 2nd " " dollar " */▼
call drawCircle 0, 0,
minX=minX-border*2; maxX=maxX+border*2 /*adjust min&max X to show border*/▼
minY=minY-border ; maxY=maxY+border /* " " " " Y " "
do h=minX to maxX; if @.h.0==@. then @.h.0='─'; end /* ◄───────────┘ */
/* [↑] define the vertical grid.*/▼
do v=minY
do y=maxY by -1 to
say aRow /*display a single row of the grid. */
end /*y*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
drawCircle: procedure expose @. minX maxX minY maxY /* [↓] Y is defined as R*/
parse arg xx,yy,r 1 y,plotChar;
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
call plotPoint xx+y, yy+x
call plotPoint xx+y, yy-x
call plotPoint xx+x, yy-y
call plotPoint xx-y, yy+x
call plotPoint xx-x, yy+y
call plotPoint xx-x, yy-y
call plotPoint xx-y, yy-x
end /*x*/
return
/*────────────────────────────────────────────────────────────────────────────*/
plotPoint:
minY=min(minY,r); maxY=max(maxY,r) /* " " " " "
return</lang>
{{out}}
|