Constrained random points on a circle

Generates an EPS file.

var points = []
while (points.len < 100) {
    var (x, y) = 2.of{ 30.irand - 15 }...
    var r2 = (x**2 + y**2)
    if ((r2 >= 100) && (r2 <= 225)) {
        points.append([x, y])
    }
}

print <<'HEAD'
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox 0 0 400 400
200 200 translate 10 10 scale
0 setlinewidth
1 0 0 setrgbcolor
0 0 10 0 360 arc stroke
0 0 15 360 0 arcn stroke
0 setgray
/pt { .1 0 360 arc fill } def
HEAD

points.each { |pt| say "#{pt.join(' ')} pt" }
print '%%EOF'

Last updated