Constrained random points on a circle: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
Line 1,667:
 
[[File:FuzzyCircle.jpg]]
 
 
=={{header|REXX}}==
===version 1===
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 */
 
arg points low high .; $= /*allow specifications from C.L. */
if points=='' then points=100
if low=='' then low=10; low2= low**2
if high=='' 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
end /*y*/
end /*x*/
 
field.=; plotChar='O'; minY=high2; maxY=-minY; ap=words($)
 
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 /*plot*/
</lang>
Output when using default input:
<pre style="height:80ex;overflow:scroll">
O O OO
O O
O O O O O
O O
OOO O O O O
O O OO OO
O O
O O OO
OO O O
O O
O
O O O
O
OO
O
O
O
O O
O O
O O O O
O OO O
OOOO O
O O
O O
O O O O
O OOO O
O O O O O
O O O O OO
OO
</pre>
===version 2===
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 */
 
arg points low high .; $= /*allow specifications from C.L. */
if points=='' then points=100
if low=='' then low=10; low2= low**2
if high=='' 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
end /*y*/
end /*x*/
 
field.=; plotChar='O'; minY=high2; maxY=-minY; ap=words($)
 
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 /*plot*/
</lang>
Output (with aspect adjustment) when using default input:
<pre style="height:80ex;overflow:scroll">
O
O O
O O O O O O
O O O O
O O O O O
O O O
O O O
O O O
O O O O
O O O O
O O
O
O O
O O O O
O O O
O O
O O
O O
O O O
O
O O O O O
O O O
O O O
O O O O O O
O O O
O O O O
O
O O O O
</pre>
 
=={{header|Ruby}}==