Constrained random points on a circle: Difference between revisions
Content added Content deleted
(Simpler D version) |
|||
Line 692: | Line 692: | ||
/ / / / / / / / |
/ / / / / / / / |
||
/ / /</pre> |
/ / /</pre> |
||
=={{header|Icon}} and {{header|Unicon}}== |
|||
Generate random points in the bounded by the outside edge. Reject any found out of the prescribed bounds and stop when the required numbers of points have been generated. |
|||
<lang Icon>link graphics |
|||
procedure main(A) # points, inside r, outside r in pixels - default to task values |
|||
points := \A[1] | 100 |
|||
outside := \A[2] | 15 |
|||
inside := \A[3] | 10 |
|||
wsize := integer(2.2*outside) |
|||
wsize <:= 150 |
|||
center := wsize/2 |
|||
WOpen("size="||wsize||","||wsize,"bg=black","fg=white") | stop("Unable to open window") |
|||
until(points -:= 1) <= 0 do { |
|||
x := ?(2*outside)-outside # random x |
|||
y := ?(2*outside)-outside # and y |
|||
if (inside <= integer(sqrt(x^2+y^2)) ) <= outside then |
|||
DrawPoint(x + center,y + center) |
|||
} |
|||
WDone() |
|||
end</lang> |
|||
=={{header|J}}== |
=={{header|J}}== |