Anonymous user
Constrained random points on a circle: Difference between revisions
Constrained random points on a circle (view source)
Revision as of 23:50, 17 June 2014
, 10 years ago→{{header|REXX}}: changed indentations, whitespace, comments, added comments, elided STYLE from PRE html tag.
Underscore (talk | contribs) (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 .
if points=='' then points=100
if low=='' then
if high==''
$=
do x=-high; x2=x*x
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*/
do j=1 for points
parse value word($,random(1,ap)) with x ',' y
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\=='' 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>
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 .
if points=='' then points=100
if low=='' then
if high==''
$=
do x=-high; x2=x*x
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*/
do j=1 for points
parse value word($,random(1,ap)) with x ',' y
field.y=overlay(plotChar, field.y, 2*x+2*high+1)
minY=min(minY,y); maxY=max(maxY,y) /*plot restricting. */
end /*j*/
do y=minY to maxY
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>
O
O O
|