  % Title "Intersections Demo"
 '% Animated
 '% ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  uses consoleG
  uses GLO2\GeoPlanar
  uses chaos

  sub boundaries()
  ================
  indexbase 0

  string tab="    "
  point  p
  int    a,i,j,k

  seed=0x123567

  line  d[30]
  int n=7
  CreatePolylines(d,0,0,n)



  'shading
  'flat 'default
  '
  color 0,1,1
  'printl "Inside " tab p.x tab p.y

  scale 10,10

  move 1.5,-1.2
  '
  color 0,1,1

  for i=0 to n-1
    drawline @d[i]
  next
  '
  point pio
  point pd[100]
  int pc
  line dd
  '
  'hatch
  pio={0,-2}
  for j=-20 to 20
    pio.x+=0
    pio.y+=0.1
    dd={-100,-100+pio.y, 100,100+pio.y}
    gosub LinesInside
  next
'cross hatch
  pio={0,-3}
  for j=-30 to 30
    pio.x+=0
    pio.y+=0.1
    dd={-100,100+pio.y, 100,-100+pio.y}
    gosub LinesInside
  next
  exit sub
  '
  LinesInside:
  ============
  color 1,1,0
  'pointsize 4
  pc=0
  for i=0 to n-1
   a=intersected d[i],dd,p
   if a
     pd[pc]=p : pc++
   endif
  next
  '
  'sort points in ascending order
  int e=pc-1
  for i=0 to e-1
    for k=i+1 to e
      if pd[k].x<pd[i].x
        swap pd[i],pd[k]
      endif
    next
  next
  if pc
    'draw interior lines
    color 1,1,0
    for i=0 to e step 2
      k=i+1
      if k<=e
        dd={ pd[i].x,pd[i].y, pd[k].x,pd[k].y }
        drawline @dd
      endif
    next
  endif
  ret  
 
  end sub


  sub main()
  ==========
  string s
  cls 0,0,0
  pushstate
  scale 2,2
  'typeface=1
  printl "Inside / Outside Hatching"
  popstate
  '
  move 0,-2
  '
  PushState
  move 1,-1
  boundaries()
  PopState
  '
  
  end sub

  EndScript
