Anonymous user
Bitmap/Midpoint circle algorithm: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.) |
|||
Line 1,955:
<br>a good aspect ratio.
The program automatically shows all of the plot's points by finding the minimum and maximum '''X''','''Y''' coördinates.
<lang rexx>/*REXX program plots three circles using midpoint/Bresenham's circle algorithm. */
@.= '·' /*fill the array with middle─dots char.*/
minX= 0;
call drawCircle 0, 0, 8, '#' /*plot 1st circle with pound character.*/
call drawCircle 0, 0, 11, '$' /* " 2nd " " dollar " */
call drawCircle 0, 0, 19, '@' /* " 3rd " " commercial at. */
border=
minX= minX - border*2; maxX= maxX + border*2
minY= minY - border ; maxY= maxY +
if @.0.0==@. then @.0.0= '┼'
/*define the plot's horizontal grid──┐ */
do h=minX to maxX; if @.h.0==@. then @.h.0= '─'; end
do v=minY to maxY; if @.0.v==@. then @.0.v= '│'; end
/*define the plot's vertical grid───┘ */
do y=maxY by -1 to minY; _= /* [↓] draw grid from top ──► bottom.*/
do x=minX to maxX; _= _ || @.x.y
end /*x*/ /* [↑] a grid row should be finished. */
say _ /*display a single row of the grid. */
Line 1,978:
/*──────────────────────────────────────────────────────────────────────────────────────*/
drawCircle: procedure expose @. minX maxX minY maxY
parse arg xx,yy,r 1 y,plotChar; fx= 1;
f= 1 - r
do x=0 while x<y /*
if f>=0 then do; y= y - 1; fy= fy + 2; f= f + fy;
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*/ /* [↑] place plot points ══► plot.
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
plotPoint:
{{out|output|text= when using the default inputs:}}
<pre>
·······················│·······················
|