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

  1. * Plot graph (Polar).
  2. * Parameter:
  3. * 1) cEquation (For radius) in terms of X.  TYPE = Character.
  4. * 2) nFrom. Where to stop counting for X.  TYPE = Numeric.
  5. * 3) nTo. Where to start counting for X.  TYPE = Numeric.
  6. * 4) nStepInc.  Step increment.  TYPE = Numeric.
  7. * 5) nEquColor.  TYPE = Numeric.
  8. * 6) lConnect.  If the previous point is connected to the cuurnt point with a line.  TYPE = Logical.
  9. * 7) nXCenter.  Point on form where x = 0.  TYPE = Numeric.
  10. * 8) nYCenter.  Point on form where y = 0.  TYPE = Numeric.
  11. * 9) lAddCoords.  If you should add coordinate lines.  TYPE = Logical.
  12. * 10) frmFormName.  Name for form to write on.  TYPE = Character.
  13. * 11) nEquScale. Scale.  TYPE = Numeric.
  14. PARAMETER cEquation,nFrom,nTo,nStepInc,nEquColor,lConnect,nXCenter,nYCenter,lAddCoords,frmFormName,nEquScale
  15.     PRIVATE nOldY,m.nOldX,nTempMaxNum
  16.     m.nTempMaxNum = 30000
  17.  
  18. IF PARAMETERS()    < 10
  19.     #define PGRAPH_LOC "This program requires multiple parameters."
  20.     WAIT WINDOW PGRAPH_LOC
  21.     RETURN
  22. ENDIF
  23.  
  24.     IF TYPE('nEquScale') <> "N"
  25.         nEquScale = 1
  26.     ENDIF    
  27.  
  28.     IF lAddCoords
  29.         * Add coordinate lines.  R=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.     ** Calcuate old values for x,y (m.nOldX,m.nOldY).  Used if connect is True.
  36.  
  37.     m.X = m.nFrom
  38.     m.nR = eval(m.cEquation)
  39.     m.nOldX = m.nR*cos(x)*nEquScale
  40.     m.nOldY = m.nR*sin(x)*nEquScale
  41.  
  42.      ** Calculate all radius and angle vales by ranging x from the "FROM" nTo the "nTo" parameters.
  43.  
  44.     frmFormName.forecolor = m.nEquColor
  45.     FOR m.x = nFrom to nTo STEP m.nStepInc
  46.         m.nR = eval(m.cEquation)
  47.         tempplotx = m.nR*cos(m.x)*nEquScale
  48.         tempploty = m.nR*sin(m.x)*nEquScale
  49.         IF m.lConnect
  50.             IF m.nYCenter-m.nOldY < m.nTempMaxNum and m.nYCenter-tempploty < m.nTempMaxNum and m.nYCenter-m.nOldY > m.nTempMaxNum*-1 and m.nYCenter-tempploty > m.nTempMaxNum*-1
  51.                 frmFormName.line(m.nOldX+m.nXCenter,m.nYCenter-m.nOldY,tempplotx+m.nXCenter,m.nYCenter-tempploty)
  52.             ENDIF
  53.         ELSE
  54.             IF m.nYCenter-tempploty < m.nTempMaxNum and m.nYCenter-tempploty > m.nTempMaxNum*-1
  55.                 frmFormName.pset(tempplotx+m.nXCenter,m.nYCenter-tempploty)
  56.             ENDIF
  57.         ENDIF
  58.         m.nOldX = tempplotx
  59.         m.nOldY = tempploty
  60.     ENDFOR
  61.     frmFormName.forecolor = rgb(0,0,0)
  62. RETURN
  63.  
  64.  
  65.