diff options
Diffstat (limited to 'ipl/gprocs/randarea.icn')
-rw-r--r-- | ipl/gprocs/randarea.icn | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/ipl/gprocs/randarea.icn b/ipl/gprocs/randarea.icn new file mode 100644 index 0000000..130a0a4 --- /dev/null +++ b/ipl/gprocs/randarea.icn @@ -0,0 +1,65 @@ +############################################################################ +# +# File: randarea.icn +# +# Subject: Procedures to generate random points in areas +# +# Author: Ralph E. Griswold +# +# Date: May 2, 2001 +# +############################################################################ +# +# This file is in the public domain. +# +############################################################################ +# +# These procedures generate randomly selected points with specified +# areas. +# +############################################################################ +# +# Links: gobject +# +############################################################################ + +link gobject + +procedure randrect(x, y, w, h) + + w := integer(w) | stop("*** bad value") + h := integer(h) | stop("*** bad value") + + x -:= 1 + y -:= 1 + + suspend Point(x + ?|w, y + ?h) + +end + +procedure randellip(x, y, w, h) + local r1, r2, xc, yc, xp, yp, xq, yq, theta, rp, r + + w := integer(w) | stop("*** bad value") + h := integer(h) | stop("*** bad value") + + r1 := w / 2 + r2 := h / 2 + xc := x + r1 + yc := y + r2 + + x -:= 1 + y -:= 1 + + repeat { + xq := x + ?w + yq := y + ?h + xp := xq - xc + yp := yq - yc + theta := -atan(yp, xp) + rp := sqrt(xp ^ 2 + yp ^ 2) + r := sqrt((r1 * cos(theta)) ^ 2 + (r2 * sin(theta)) ^ 2) + if r > rp then suspend Point(xq, yq) + } + +end |