Re: Ellipse

From: Bob Lackman (rll AT unknown)
Date: Tue Nov 26 1996 - 10:08:12 MST


> Anybody
>
> How do you draw an ellipse with NCAR Graphics?
>
> jerome.heffter AT unknown

        Here is one way. Call the following program ellipse.f
        Then compile it with the command

        ncargf77 ellipse.f

        Put the data defined by LINE in a file called data.ellipse
        (a location, width, height, line width, line color & fill color)
        and execute the command

        a.out < data.ellipse

        The output will go into a file called gmeta. You can view
        it with ctrans -d X11 gmeta

        If you want the ellipse rotated you would have to rotate the
        BRDX,BRDY coordinates.

        By putting the data in a file you don't have to recompile to
        run new ellipses.

        You could make this into a subroutine ellipse to be called by
        other programs.

        Bob- rll AT unknown
C---------------------------------------------------------------------
C PROGRAM ELLIPSE
C
C The arrays BRDX and BRDY will be used to hold the ellipse points.
C
        DIMENSION BRDX(365),BRDY(365)
        CHARACTER*90 LINES
        INTEGER FCOLOR
        REAL LWIDTH
C
C Define the constant by which one multiplies to convert an angle from
C degrees to radians.
C
        DATA DTOR / .017453292519943 /
C
C Open GKS.
C
        CALL OPNGKS
C
C Define the mapping from the user system to the fractional system.
C
        CALL SET (0.,1.,0.,1.,0.,1.,0.,1.,1)
C
C Set up colors.
C
C Index Color Index Color Index Color
C
C 0 blue 4 sky blue 8 pink
C 1 white 5 cyan 9 salmon
C 2 green 6 magenta
C 3 yellow 7 tan
C
        CALL GSCR (1,0,0.00,0.25,0.75)
        CALL GSCR (1,1,1.00,1.00,1.00)
        CALL GSCR (1,2,0.00,0.75,0.25)
        CALL GSCR (1,3,1.00,1.00,0.00)
        CALL GSCR (1,4,0.20,0.56,0.80)
        CALL GSCR (1,5,0.00,1.00,1.00)
        CALL GSCR (1,6,1.00,0.00,1.00)
        CALL GSCR (1,7,0.86,0.58,0.44)
        CALL GSCR (1,8,0.73,0.56,0.56)
        CALL GSCR (1,9,0.43,0.26,0.26)
C
C Read is XCEN,YCEN,XDIS,YDIS,LWIDTH,LCOLOR,FCOLOR
C
  102 READ (5,'(A88)',END=104) LINES
C
C Decode the line
C
        READ (LINES(2:32),'(5F5.0,2I3)',END=104)
     + XCEN,YCEN,XDIS,YDIS,LWIDTH,LCOLOR,FCOLOR
C PRINT *,' XCEN,YCEN,XDIS,YDIS,LWIDTH,LCOLOR,FCOLOR'
C PRINT *, XCEN,YCEN,XDIS,YDIS,LWIDTH,LCOLOR,FCOLOR
C .5 .5 .2 .4 3. 6 7
C
C XCEN, YCEN are the center of the ellipse
C XDIS, YDIS are the x radius and y radius of the ellipse
C LWIDTH is the ellipse line width (1. is default)
C LCOLOR is the line color
C FCOLOR is the fill color
C
C Set the line width, line color, and fill color
C
        CALL GSLWSC(LWIDTH)
        CALL GSPLCI(LCOLOR)
        CALL GSFACI(FCOLOR)
C
C Place an ellipse on the frame.
C
        XD2 = XDIS*XDIS
        DO 98 I=1,361
          ANGL=DTOR*REAL(I-1)
          DX = XDIS*COS(ANGL)
          BRDX(I )=XCEN + DX
          X2 = DX*DX
          DY = YDIS*SQRT(1.-X2/XD2)
          IF(I.LT.182) THEN
          BRDY(I )=YCEN + DY
          ELSE
          BRDY(I )=YCEN - DY
          END IF
  98 CONTINUE
        NPTS = 361
C
C Fill the ellipse if the fill color index is greater than 0.
C
        IF(FCOLOR.GT.0) THEN
        CALL GSFAIS(1)
        CALL GFA(NPTS,BRDX,BRDY)
        END IF
C
C Draw the ellipse.
C
        CALL GPL (NPTS,BRDX,BRDY)
        CALL SFLUSH
  104 CONTINUE
        CALL FRAME
C
C Close GKS.
C
        CALL CLSGKS
C
C Done.
C
        STOP
C
      END



This archive was generated by hypermail 2b29 : Wed Jun 28 2000 - 09:44:56 MDT