home *** CD-ROM | disk | FTP | other *** search
- // Plotting functions for Plotter
- // ⌐ 1999-2000 Glenn Strong <Glenn.Strong@cs.tcd.ie>
- // Issued under the GNU General Public license, version 2
-
- // Plot the function given by f$ between 0 and Max
- EXTERNAL Graph_Pass:(f$)
-
- // Generate the permutations of the functions to
- // plot. The number of ▒ symbols controls the number
- // of permutations.
- EXTERNAL PlotPerms:(p%,max%)
-
- // The magic "plusminus" symbol.
- #define PLUSMINUS %▒
-
- // Plot the function given by f$ between 0 and Max
- // f$ is the function (a copy of orig$). items%
- // lists the positions of magic characters like ▒
- PROC PlotFunction:(orig$)
- GLOBAL f$(255), items%(255)
- LOCAL i%, j%, c%
- f$=orig$
- i%=1
- j%=1
- // Note the positions of magic characters (like ▒)
- DO
- c%=PEEKB(ADDR(f$)+i%)
- IF c% = PLUSMINUS
- items%(j%)=i%
- j%++
- ENDIF
- i%++
- UNTIL i%=LEN(orig$)
-
- // If there were no magic characters then we can
- // just plot the function. Otherwise we find the
- // permutations of the string that are functions
- IF j%=1
- GRAPH_PASS:(f$)
- ELSE
- PlotPerms:(1,j%)
- ENDIF
- ENDP
-
- // Pass through the function in f$: generate & plot
- // the functions
- PROC PlotPerms:(p%,max%)
- EXTERNAL f$, items%()
-
- // Base case for recursion
- IF p%=max% : RETURN : ENDIF
-
- // Sub in a + sign for ▒.
- IF p%=1 OR (p%>1 AND (PEEKB(ADDR(f$)+p%)=%( ))
- POKEB ADDR(f$)+items%(p%),32 // unary + messes up
- ELSE
- POKEB ADDR(f$)+items%(p%),%+
- ENDIF
- PlotPerms:(p%+1,max%)
- GRAPH_PASS:(f$)
-
- // Sub in a - sign for ▒.
- POKEB ADDR(f$)+items%(p%),%-
- PlotPerms:(p%+1,max%)
- GRAPH_PASS:(f$)
- ENDP
-
- // Draw the function in f$ within the bounds set by
- // the global options. OPL's EVAL statement is used to
- // actually do the function calculation.
- PROC Graph_Pass:(f$)
- EXTERNAL WinH%, WinW%, RMin, RMax, Mesh&, DrawWindow%
- EXTERNAL Zoom, XCent%, YCent%, Offscreen%, Uselines%
- GLOBAL x // EVAL's cannot reference locals
- LOCAL y, max%, isMove%, Step, Scale
-
- Step = RMax/Mesh&
- IF Zoom > 0
- Scale = (WinW%/(RMax-RMin)) * Zoom
- ELSE
- Scale = (WinW%/(RMax-RMin)) / (-Zoom)
- ENDIF
-
- isMove%=KTrue%
- x=RMin
- BUSY "Plotting..."
- ONERR ErrHandler
- gUSE DrawWindow%
-
- // Vary X from RMin to RMax in steps of (1/mesh)
- // and calculate the function from each point
- WHILE x <= RMax
- y=(EVAL(f$))*Scale
- IF (yCent%-y > (WinH%*2)) AND (NOT Offscreen%)
- isMove%=KTrue%
- ENDIF
- IF isMove%
- gAT (x*Scale)+xCent%, yCent%-y
- isMove%=KFalse%
- ELSEIF UseLines%
- GLINETO (x*Scale)+xCent%, yCent%-y
- ELSE
- gAT (x*Scale)+xCent%, yCent%-y
- gLINEBY 0, 0
- ENDIF
- x+=Step
- CONTINUE // skip the error handler if there
- // was no error!
- ErrHandler::
- // This is somewhat odd. We skip some errors, and
- // handle others sensibly:
- IF ERR = KErrDivideByZero%
- isMove% = KTrue% // Try and draw a hole in the graph
- ELSEIF (ERR = KErrUnderflow%) OR (ERR = KErrOverflow%) OR (ERR = KErrInvalidArgs%)
- isMove% = KTrue% // These are real errors, but we try and proceed anyway
- ELSE
- // Real errors that we report.
- ALERT(ERR$(ERR),"("+GEN$(ERR,3)+")")
- BUSY OFF : ONERR OFF : RETURN
- ENDIF
- x+=Step // We missed this when we entered the handler
- ENDWH
- BUSY OFF
- ONERR OFF
- ENDP
-
- // Draw the axis
- PROC Axis:
- EXTERNAL WinH%, WinW%, RMin, RMax
- EXTERNAL Zoom, yCent%, xCent%, DrawWindow%
- LOCAL x, y, i%, max%, Scale
-
- IF Zoom > 0
- Scale = (WinW%/(RMax-RMin)) * Zoom
- ELSE
- Scale = (WinW%/(RMax-RMin)) / (-Zoom)
- ENDIF
-
- gUSE DrawWindow%
-
- gAT (RMin*Scale)+XCent%, yCent%
- gLINETO (RMax*Scale)+XCent%, yCent%
-
- // Domain max size now known.
- gAT xCent%, 0
- gLINETO xCent%, WinH%
-
- max% = Mod&:(WinW%,Scale)
- i%=RMin
- gFONT KFontArialNormal8&
- DO
- gAT i%*Scale+XCent%, yCent%
- gLineBy 0,5
- IF i% <> 0
- gAT i%*Scale+XCent%-5, yCent%+12
- gPRINT i%
- ENDIF
- gAT XCent%,yCent%-(Scale*i%)
- gLineBy 5,0
- IF i% <> 0
- gAT XCent%+5,yCent%-(Scale*i%)
- gPRINT i%
- ENDIF
- i%++
- UNTIL i% > RMax
- ENDP
-
- // Draw a caption for the graph. Overprint "<" and "_" to
- // get inequalities.
- PROC Caption:
- EXTERNAL WinH%, f$, RMin, RMax, overPrintCount%
- LOCAL ypos%
- gFONT KFontArialNormal11&
- ypos% = WinH% - 6 - (overPrintCount%*11)
-
- gAT 5,ypos%
- gPRINT f$+" "+GEN$(RMin,3)+" <"
- gMOVE -gTWIDTH("<"),0
- gPRINT "_ x <"
- gMOVE -gTWIDTH("<"),0
- gPRINT "_ "+GEN$(RMax,3)
- ENDP