home *** CD-ROM | disk | FTP | other *** search
/ Total C++ 2 / TOTALCTWO.iso / vfp5.0 / vfp / samples / solution / forms / graphics / cgraph.prg < prev    next >
Encoding:
Text File  |  1996-08-21  |  2.3 KB  |  64 lines

  1. * Plot graph.
  2. * Parameter:
  3. * 1) cEquation in terms of X.  Will plot the answer as Y.  TYPE = Character.
  4. * 2) nStepInc.  Step increment.  TYPE = Numeric.
  5. * 3) nEquColor.  TYPE = Numeric.
  6. * 4) lConnect.  If the previous point is connected to the current point with a line.  TYPE = Logical.
  7. * 5) nXCenter.  Point on form where x = 0.  TYPE = Numeric.
  8. * 6) nYCenter.  Point on form where y = 0.  TYPE = Numeric.
  9. * 7) lAddCoords.  If you should add coordinate lines.  TYPE = Logical.
  10. * 8) frmFormName.  Name for form to write on.  TYPE = Character.
  11. * 9) nEquScale. Scale to graph equation.  TYPE = Numeric.
  12.  
  13. PARAMETER cEquation,nStepInc,nEquColor,lConnect,nXCenter,nYCenter,lAddCoords,frmFormName,nEquScale
  14.     PRIVATE nOldY,nOldX,nTempMaxNum
  15.     
  16. IF PARAMETERS()    < 9
  17.     #define CGRAPH_LOC "This program requires multiple parameters."
  18.     WAIT WINDOW CGRAPH_LOC
  19.     RETURN
  20. ENDIF
  21.  
  22.     ** Set maxiumn values of plotting.
  23.     nTempMaxNum = 30000
  24.     IF TYPE('nEquScale') <> "N"
  25.         nEquScale = 1
  26.     ENDIF    
  27.  
  28.     IF lAddCoords
  29.         * Add coordinate lines.  X=0 and Y=0.
  30.         frmFormName.forecolor = rgb(0,0,0)
  31.         frmFormName.line(m.nXCenter,0,m.nXCenter,frmFormName.height)
  32.         frmFormName.line(0,m.nYCenter,frmFormName.width,m.nYCenter)
  33.     ENDIF    
  34.  
  35.     
  36.     ** Calcuate old values for x,y (nOldX,nOldY).  Used if connect is True.
  37.     nOldX = (0-m.nXCenter)/m.nEquScale
  38.     ** Need to use x for the eval of m.cEquation.
  39.     m.x = nOldX
  40.      nOldY = EVALUATE(m.cEquation)*m.nEquScale
  41.     
  42.  
  43.     frmFormName.forecolor = m.nEquColor
  44.      ** Loop from left to right all values of x and calculate the y value.
  45.     FOR m.nXTemp = (0-m.nXCenter)/m.nEquScale TO (frmFormName.width-m.nXCenter)/m.nEquScale step m.nStepInc/m.nEquScale
  46.         m.x = m.nXTemp
  47.         nY = EVALUATE(m.cEquation)*m.nEquScale
  48.         IF m.lConnect
  49.             IF m.nYCenter-nOldY < m.nTempMaxNum and m.nYCenter-m.nY < m.nTempMaxNum and m.nYCenter-nOldY > m.nTempMaxNum*-1 and m.nYCenter-nY > m.nTempMaxNum*-1
  50.                 frmFormName.line(m.nXCenter+(nOldX*m.nEquScale),m.nYCenter-nOldY,m.nXCenter+(m.nXTemp*m.nEquScale),m.nYCenter-m.nY)
  51.             ENDIF
  52.         ELSE
  53.             IF m.nYCenter-m.nY < m.nTempMaxNum and m.nYCenter-m.nY > m.nTempMaxNum*-1
  54.                 frmFormName.pset(m.nXCenter+(m.nXTemp*m.nEquScale),m.nYCenter-y)
  55.             ENDIF
  56.         ENDIF
  57.         nOldX = m.nXTemp
  58.         nOldY = m.nY 
  59.     ENDFOR
  60.     frmFormName.forecolor = rgb(0,0,0)
  61. RETURN
  62.  
  63.  
  64.