Constrained random points on a circle: Difference between revisions

m
→‎{{header|REXX}}: changed indentations, whitespace, comments, added comments, elided STYLE from PRE html tag.
(Added Hy.)
m (→‎{{header|REXX}}: changed indentations, whitespace, comments, added comments, elided STYLE from PRE html tag.)
Line 1,893:
No aspect adjustment is done in version of the REXX program.
<lang rexx>/*REXX program gens 100 random points in an annulus: 10 ≤ √(x²≤y²) ≤ 15 */
parse arg points low high .; $= /*allow argsparms from command line. */
if points=='' then points=100
if low=='' then low=10; low2= low**2 /*define a square shortcut.*/
if high=='' then then high=15; high2=high**2 /* " " " " */
$=
 
do x=-high; x2=x*x /*gen all possible annulus points*/
if x<0 & x2>high2 then iterate
if x>0 & x2>high2 then leave
do y=-high; y2=y*y; s=x2+y2
if (y<0 & s>high2) | s<low2 then iterate
if y>0 & s>high2 then leave
$=$ x','y /*add a point-set to the $ list. */
end /*y*/
end /*x*/
 
field.=; plotChar='O'; minY=high2; maxY=-minY; ap=words($); field.=
 
do j=1 for points /*"draw" the x,y points [char O].*/
parse value word($,random(1,ap)) with x ',' y /*pick random point.*/
field.y=overlay(plotChar, field.y, x+high+1) /*"draw: the point. */
minY=min(minY,y); maxY=max(maxY,y) /*plot restricting. */
end /*j*/
 
do y=minY to maxY; if field.y=='' then iterate; say field.y; end /*plotdisplay the annulus to screen. */</lang>
if field\=='' then say field.y /*Not blank? Then display it. */
end /*y*/
/*stick a fork in it, we're done.*/</lang>
'''output''' when using default input:
<pre>
<pre style="overflow:scroll">
O O OO
O O
Line 1,953 ⟶ 1,956:
Aspect adjustment is done is this version of the REXX program.
<lang rexx>/*REXX program gens 100 random points in an annulus: 10 ≤ √(x²≤y²) ≤ 15 */
parse arg points low high .; $= /*allow argsparms from command line. */
if points=='' then points=100
if low=='' then low=10; low2= low**2 /*define a square shortcut.*/
if high=='' then then high=15; high2=high**2 /* " " " " */
$=
 
do x=-high; x2=x*x /*gen all possible annulus points*/
if x<0 & x2>high2 then iterate
if x>0 & x2>high2 then leave
do y=-high; y2=y*y; s=x2+y2
if (y<0 & s>high2) | s<low2 then iterate
if y>0 & s>high2 then leave
$=$ x','y /*add a point-set to the $ list. */
end /*y*/
end /*x*/
 
field.=; plotChar='O'; minY=high2; maxY=-minY; ap=words($); field.=
 
do j=1 for points /*"draw" the x,y points [char O].*/
parse value word($,random(1,ap)) with x ',' y /*pick random point.*/
field.y=overlay(plotChar, field.y, 2*x+2*high+1) /*"draw: the point. */
minY=min(minY,y); maxY=max(maxY,y) /*plot restricting. */
end /*j*/
 
do y=minY to maxY; if field.y=='' then iterate; say field.y; end /*plotdisplay the annulus to screen. */</lang>
if field\=='' then say field.y /*Not blank? Then display it. */
end /*y*/
/*stick a fork in it, we're done.*/</lang>
'''output''' (with aspect adjustment) when using default input:
<pre>
<pre style="overflow:scroll">
O
O O