############################################################################ # # 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