home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Fortran.51 / DISK6 / SINE.FO$ / SINE.bin
Text File  |  1989-01-27  |  5KB  |  189 lines

  1. CC  SINE.FOR - Illustrates basic graphics commands.
  2.  
  3.       INCLUDE  'FGRAPH.FI'
  4.  
  5.       CALL graphicsmode()
  6.       CALL drawlines()
  7.       CALL sinewave()
  8.       CALL drawshapes()
  9.       CALL endprogram()
  10.       END
  11.  
  12. C     Definitions of subroutines go here . . .
  13.  
  14.  
  15.       SUBROUTINE graphicsmode() 
  16.  
  17.       INCLUDE  'FGRAPH.FD'
  18.  
  19.       INTEGER*2            dummy, maxx, maxy
  20.       RECORD /videoconfig/ myscreen
  21.       COMMON               maxx, maxy
  22.  
  23. C
  24. C     Find graphics mode.
  25. C
  26.       CALL getvideoconfig( myscreen )
  27.       SELECT CASE( myscreen.adapter )
  28.          CASE( $CGA )
  29.             dummy = setvideomode( $HRESBW )
  30.          CASE( $OCGA )
  31.             dummy = setvideomode( $ORESCOLOR )
  32.          CASE( $EGA, $OEGA )
  33.             IF( myscreen.monitor .EQ. $MONO ) THEN
  34.                 dummy = setvideomode( $ERESNOCOLOR )
  35.             ELSE
  36.                 dummy = setvideomode( $ERESCOLOR )
  37.             END IF
  38.          CASE( $VGA, $OVGA, $MCGA )
  39.             dummy = setvideomode( $VRES2COLOR )
  40.          CASE( $HGC )
  41.             dummy = setvideomode ( $HERCMONO )
  42.          CASE DEFAULT
  43.             dummy = 0
  44.       END SELECT
  45.  
  46.       IF( dummy .EQ. 0 ) STOP 'Error:  cannot set graphics mode'
  47.  
  48. C
  49. C     Determine the minimum and maximum dimensions.
  50. C
  51.       CALL getvideoconfig( myscreen )
  52.       maxx = myscreen.numxpixels - 1
  53.       maxy = myscreen.numypixels - 1
  54.       END
  55.  
  56. CC  NEWX - This function finds new x coordinates.
  57.  
  58.       INTEGER*2 FUNCTION newx( xcoord )
  59.  
  60.       INTEGER*2 xcoord, maxx, maxy
  61.       REAL*4    tempx
  62.       COMMON    maxx, maxy
  63.  
  64.       tempx = maxx / 1000.0
  65.       tempx = xcoord * tempx + 0.5
  66.       newx  = tempx 
  67.       END
  68.  
  69.  
  70. CC  NEWY - This function finds new y coordinates.
  71.  
  72.       INTEGER*2 FUNCTION newy( ycoord )
  73.  
  74.       INTEGER*2 ycoord, maxx, maxy
  75.       REAL*4    tempy
  76.       COMMON    maxx, maxy
  77.  
  78.       tempy = maxy / 1000.0
  79.       tempy = ycoord * tempy + 0.5
  80.       newy  = tempy
  81.       END
  82.  
  83.  
  84. CC  DRAWLINES - This subroutine draws a box and several lines.
  85.  
  86.       SUBROUTINE drawlines()
  87.  
  88.       INCLUDE  'FGRAPH.FD'
  89.  
  90.       EXTERNAL         newx,newy
  91.       INTEGER*2        dummy, newx, newy, maxx, maxy
  92.       RECORD /xycoord/ xy
  93.       COMMON           maxx, maxy
  94.  
  95. C
  96. C     Draw the box.
  97. C
  98.       dummy = rectangle( $GBORDER, 0, 0, maxx, maxy )
  99.       CALL setvieworg( 0, newy( INT2( 500 ) ), xy )
  100. C
  101. C     Draw the lines.
  102. C
  103.       CALL    moveto( 0, 0, xy )
  104.       dummy = lineto( newx( INT2( 1000 ) ), 0 )
  105.       CALL    setlinestyle( #AA3C )
  106.       CALL    moveto( 0, newy( INT2( -250 ) ), xy )
  107.       dummy = lineto( newx( INT2( 1000 ) ), newy( INT2( -250 ) ) )
  108.       CALL    setlinestyle( #8888 )
  109.       CALL    moveto( 0, newy( INT2( 250 ) ), xy )
  110.       dummy = lineto( newx( INT2( 1000 ) ), newy( INT2( 250 ) ) )
  111.       END
  112.  
  113.  
  114. CC  SINEWAVE - This subroutine calculates and plots a sine wave.
  115.  
  116.       SUBROUTINE sinewave()
  117.  
  118.       INCLUDE  'FGRAPH.FD'
  119.  
  120.       INTEGER*2        dummy, newx, newy, locx, locy, i
  121.       DOUBLE PRECISION rad, PI
  122.       EXTERNAL         newx, newy
  123.  
  124.       PARAMETER        ( PI = 3.14159 )
  125.  
  126. C
  127. C     Calculate each position and display it on the screen.
  128. C
  129.       DO i = 0, 999, 3
  130.          rad   = -SIN( PI * i / 250.0 )
  131.          locx  = newx( i )
  132.          locy  = newy( INT2( rad * 250.0 ) )
  133.          dummy = setpixel( locx, locy )
  134.       END DO
  135.       END
  136.  
  137.  
  138. CC  DRAWSHAPES - This subroutine draws two boxes and two ellipses.
  139.  
  140.       SUBROUTINE drawshapes()
  141.  
  142.       INCLUDE  'FGRAPH.FD'
  143.  
  144.       EXTERNAL  newx, newy
  145.       INTEGER*2 dummy, newx, newy
  146.  
  147. C
  148. C     Create a masking (fill) pattern.
  149. C
  150.       INTEGER*1 diagmask(8),  linemask(8) 
  151.       DATA diagmask / #93, #C9, #64, #B2, #59, #2C, #96, #4B /
  152.       DATA linemask / #FF, #00, #7F, #FE, #00, #00, #00, #CC /
  153. C     Draw the rectangles.
  154. C
  155.       CALL setlinestyle( #FFFF )
  156.       CALL setfillmask( diagmask )
  157.       dummy = rectangle( $GBORDER,
  158.      +                  newx( INT2( 50  ) ), newy( INT2( -325 ) ),
  159.      +                  newx( INT2( 200 ) ), newy( INT2( -425 ) ) )
  160.       dummy = rectangle( $GFILLINTERIOR,
  161.      +                  newx( INT2( 550 ) ), newy( INT2( -325 ) ),
  162.      +                  newx( INT2( 700 ) ), newy( INT2( -425 ) ) )
  163. C
  164. C     Draw the ellipses.
  165. C
  166.       CALL setfillmask( linemask )
  167.       dummy = ellipse( $GBORDER,
  168.      +                newx( INT2( 50  ) ), newy( INT2( 325 ) ),
  169.      +                newx( INT2( 200 ) ), newy( INT2( 425 ) ) )
  170.       dummy = ellipse( $GFILLINTERIOR,
  171.      +                newx( INT2( 550 ) ), newy( INT2( 325 ) ),
  172.      +                newx( INT2( 700 ) ), newy( INT2( 425 ) ) )
  173.  
  174.       END
  175.  
  176.  
  177. CC  ENDPROGRAM - This subroutine waits for the ENTER key to be
  178. CC  pressed, then resets the screen to normal before returning.
  179.  
  180.       SUBROUTINE endprogram()
  181.  
  182.       INCLUDE  'FGRAPH.FD'
  183.       INTEGER*2  dummy
  184.  
  185.       READ (*,*)                       ! Wait for ENTER key
  186.       dummy = setvideomode( $DEFAULTMODE )
  187.       END
  188.