/*C-----------------------------------------------------------------------
C Demonstration program for PGPLOT. This programs shows the use of
C routine PGOLIN to allow the user to draw polygons on the screen.
C As each polygon is completed, it is filled in using routine PGPOLY.
C The user positions the cursor to define the vertices of the polygon.
C He types 'A' to add a vertex at the current cursor position, 'D' to
C delete the nearest vertex, or 'X' to signal that the polygon is 
C complete. Two 'X's in succession terminates the program.
C-----------------------------------------------------------------------*/
      MAXPT=50
      X = Y = floatarray(MAXPT)
  
print " Demonstration of PGPLOT cursor routines"
print " PGLCUR and PGOLIN."
print " These routines allow you to draw polygons on the"
print " screen, using the"
print " cursor to mark the vertices."
print " PGLCUR outlines the polygon as you draw it, PGOLIN"
print " just marks the"
print " vertices. Which routine do you want to use? Type 1"
print " for PGLCUR, 2 for"
print " PGOLIN:"
      WHICH = 1
//      read "", WHICH
      if (WHICH < 1 || WHICH > 2) WHICH = 1
print " Use the cursor to choose the vertices of the polygon"
print "   Type A to add a vertex at the cursor position"
print "   Type D to delete the last vertex"
print "   Type X to close the polygon and shade it"
print "   (Type X again to exit from the program)"

//C
//C Open device for graphics.
//C
      if (pgbeg(0,plotdevice,1,1) != 1) break
//C
//C Clear the screen. Draw a frame at the physical extremities of the
//C view surface using full-screen viewport and standard window.
//C
      pgpage
      pgsvp 0.0,1.0,0.0,1.0
      pgswin 0.0,1.0,0.0,1.0
      pgbox "BC",0.1,5,"BC",0.1,5
      COL = 0
//C
//C Increment the color index and then call PGOLIN to allow the user
//C to draw a polygon.
//C
    NPT = 3
    while (NPT > 2) {
      COL = COL+1
      pgsci COL
      NPT = 0
      if (WHICH == 1) pglcur MAXPT,NPT,X,Y
      if (WHICH == 2) pgolin MAXPT,NPT,X,Y,-1
//C
//C Fill the interior of the polygon in the current color. If less
//C than three vertices were supplied, that is a signal to terminate
//C the program.  Otherwise, go back and draw another polygon.
//C
      if (NPT >= 3) {
           pgpoly NPT,X,Y
      }
    }
//C
//C Close the device and exit.
//C
      pgend
