newpage "eps", "tutorialprotect2.eps", 75, 50

# Draw a shape then mark that area as protected.
#
move 10, 10
draw 60, 40, 55, 45, 5, 15, 10, 10
stroke
protect

font "Helvetica", 4
color "blue"
let w = stringwidth("ABCD")
let counter = 0

# Draw 25 randomly positioned labels, avoiding overlaps with anything
# we have already drawn.
#
while counter < 25
do
  let x = random(75)
  let y = random(50)
  if (not protected(x, y, x + w, y + 4))
  then
    clearpath
    move x, y
    label "ABCD"
    protect x, y, x + w, y + 4
    let counter = counter + 1
  endif
done
