! ?????? on hold !! File: VisualSum !! May 26, 2003 Hubert Hohn PUBLIC PCFlag,Mac5Flag,M68KFlag,UnixFlag,xmax,ymax PUBLIC toolLft,toolRgt,toolBas,toolTop,toolhdr,toolHgt,toolWid ! tool boundaries PUBLIC winLft,winRgt,winBas,winTop,winHgt,winWid ! window PUBLIC workLft,workRgt,workBas,workTop,workMidx ! work area PUBLIC black,drkgry,drkmid,midgry,litmid,litgry,white PUBLIC backclr,red,yellow,green,cyan,blue,magenta,pink,colorscheme PUBLIC planeclr,gridclr,rimclr,axisclr,axislabelclr,titleclr,rightsclr PUBLIC numberlineclr,slotdrkclr,slotlgtclr,slideclr PUBLIC largefonts, title$, SLUmode LET toolHgt= 560 LET toolWid= 780 LET window$= "The d'Arbeloff Interactive Math Project" LET colorscheme= 0 LET title$ = "Numerical Integration and Solutions" SUB ThisProgram CALL WaveSum CLEAR END SUB !! --------------------------------------------------------- !! ------ Start TB4 Mac Header and Subs ------ !LET M68KFlag = 1 !LIBRARY "MacTools*", "HHLib.trc" !ASK PIXELS winWid,winHgt !LET winLft= 0 !LET winTop= 0 !LET winRgt= winWid-1 !LET winBas= winHgt-1 !SET WINDOW 0,winRgt,winBas,0 !CALL Palette !CLEAR ! !CALL ToolPanel !CALL ThisProgram ! !END !EXTERNAL ! !MODULE Mac4Parts ! SUB SetTextFont(font,size,style$) ! CALL MacTextFont(font) ! CALL MacTextSize(size) ! CALL MacTextFace(style$) ! END SUB ! ! SUB StringWidth(sw$,sl) ! DECLARE DEF MacStringWidth ! LET sl= MacStringWidth(sw$) ! END SUB ! ! SUB SetLineWeight(wgt) ! CALL MacPenSize(wgt,wgt) ! END SUB ! ! SUB BoxDisk(Lft,Rgt,Bas,Top) ! CALL MacPaintOval(Lft,Rgt,Bas,Top) ! END SUB !END MODULE !! --- End TB4 Mac Header and Subs --- !!--------------------------------------------------------- !!--- Start TB5 Cross-Platform header and subs --- LIBRARY "c:\TB Gold 51a\TBLibs\TrueCtrl.trc" ! windows LIBRARY "c:\TB Gold 51a\TBLibs\HHLib.trc" ! !LIBRARY ":TBLibs:TrueCtrl.trc" ! macintosh !LIBRARY "HHLib.trc" ! PUBLIC WinID DECLARE PUBLIC OBJM_SET,OBJM_SYSINFO LET winHgt= toolHgt LET winWid= toolWid DIM values(1) CALL TC_Init CALL Object(OBJM_SYSINFO,WinID,"MACHINE",system$,values()) IF system$="MAC" then LET Mac5Flag= 1 ELSE IF system$="WIN32" then LET PCFlag = 1 END IF CALL TC_SetUnitsToPixels ! 5.1 and up needs this CALL TC_GetScreenSize(scrnLft,scrnRgt,scrnBas,scrnTop) LET winLft= int((scrnRgt-scrnLft-winWid)/2) LET winRgt= winLft+winWid-1 LET winTop= int((scrnBas-scrnTop-winHgt)/2) + 10 LET winBas= winTop+winHgt-1 CALL TC_Win_Create (WinID,"TITLE",winLft,winRgt,winBas,winTop) LET values(1)= 2 CALL Object(OBJM_SET, WinID, "TYPE", "", values()) IF PCFlag=1 then ! kill dithering LET values(1)= 1 CALL Object(OBJM_SET, WinID, "SOLID MIX", "", values()) END IF LET values(1)= 0 CALL TC_SetRect(WinID,winLft,winRgt,winBas,winTop) CALL TC_Win_SetTitle(WinID,window$) CALL TC_Show(WinID) SET MODE "COLORSTANDARD" ASK PIXELS winWid,winHgt ! must follow set mode LET winLft= 0 LET winTop= 0 LET winRgt= winWid-1 LET winBas= winHgt-1 SET WINDOW 0,winRgt,winBas,0 CALL Palette IF PCFlag=1 then LET values(1)= 0 ! now force solid colors CALL Object(OBJM_SET, WinID, "SOLID MIX", "", values()) CALL TC_Win_RealizePalette(WinID) ! some PCs need this CALL TC_Win_SetFont(WinID,"arial",9,"plain") CALL StringWidth("0",sw) IF sw>7 then LET largefonts=1 else LET largefonts=0 END IF CALL TC_Win_Switch(WinID) CALL ToolPanel CALL ThisProgram CALL SetTextFont(1,12,"bold") ! now shut down and clean up LET quit$= "click the mouse or press a key to close..." CALL PlotTextCJ(workmidx,(workbas+worktop)/2,quit$,yellow) CALL TC_CleanUp END EXTERNAL MODULE TB5Parts SUB StringWidth(sw$,sl) DECLARE PUBLIC WinID LET sl= StrWidth(WinID,sw$) END SUB SUB SetLineWeight(wgt) DECLARE PUBLIC OBJM_SET DECLARE PUBLIC WinID DIM values(1) LET values(1)= wgt CALL Object(OBJM_SET,WinID, "WIDTH", "", values()) END SUB SUB SetTextFont(font,size,style$) DECLARE PUBLIC WinID,Mac5Flag,PCFlag,largefonts IF Mac5Flag=1 then SELECT CASE font CASE 4 LET font$= "Courier" CASE 16 LET font$= "Times" CASE else LET font$= "Geneva" END SELECT ELSE IF PCFlag=1 then IF largefonts=1 then IF size<12 then LET size= 6 ELSE IF size=14 then LET size= 10 ELSE IF size=18 then LET size= 12 ELSE IF size=24 then LET size= 14 ELSE IF size=12 then LET size= 8 ELSE LET size= round(72/96 * size * .8) END IF ELSE IF size<12 then LET size= 7 ELSE IF size=14 then LET size= 12 ELSE IF size=12 then LET size= 9 ELSE IF size=18 then LET size= 14 ELSE IF size=24 then LET size= 18 ELSE LET size= round(72/96 * size) END IF END IF SELECT CASE font CASE 4 LET font$= "Courier New" CASE 16 LET font$= "Times New Roman" CASE else LET font$= "Verdana" END SELECT END IF IF style$= "normal" then LET style$= "plain" CALL TC_Win_SetFont(WinID,font$,size,style$) END SUB SUB BoxDisk(Lft,Rgt,Bas,Top) BOX DISK Lft,Rgt,Bas,Top END SUB END MODULE ! --- End TB5 Cross-platform header and subs --- !! --------------------------------------------------------- !! --- Start Unix Header and Subs --- !library "HHLib.unix" !LET UnixFlag= 1 !ASK PIXELS winWid,winHgt !LET winLft= 0 !LET winTop= 0 !LET winRgt= winWid-1 !LET winBas= winHgt-1 !SET WINDOW 0,winRgt,winBas,0 !CALL Palette ! !CALL ToolPanel !CALL ThisProgram ! !END !EXTERNAL ! !MODULE UnixParts ! SHARE CharWidth ! ! SUB SetTextFont(font,size,style$) ! LET font$= "-adobe-courier-" ! IF style$= "normal" then ! LET style$= "medium-r-normal--" ! ELSE ! LET style$= "bold-r-normal--" ! END IF ! IF size=9 then ! LET size$= str$(10) ! ELSE ! LET size$= str$(size) ! END IF ! LET test= SetFont(font$&style$&size$&"*") ! ! IF size=9 then ! LET CharWidth= 6 ! ELSE IF size=12 then ! numeric output - axis labels ! LET CharWidth= 7 ! ELSE IF size=14 then ! rare ! LET CharWidth= 8 ! ELSE IF size=18 then ! rare ! LET CharWidth= 10 ! END IF ! END SUB ! ! SUB StringWidth(sw$,sl) ! string width in pixels ! ! LET sl= StrWidth(sw$) ! LET chars= len(sw$) ! LET sl = chars*CharWidth ! END SUB ! ! SUB SetLineWeight(wgt) ! ! CALL PenSize(wgt,wgt) ! END SUB ! ! SUB BoxDisk(Lft,Rgt,Bas,Top) ! CALL Fill_Circle(Lft,Rgt,Bas,Top) ! END SUB !END MODULE !! ------ End of TB Unix Header and Subs ------ ! ----------------------------------------------------------- ! *** SUB WaveSum DECLARE PUBLIC black,drkgry,drkmid,midgry,litmid,litgry,white DECLARE PUBLIC red,yellow,green,cyan,blue,magenta,colorscheme DECLARE PUBLIC planeclr,gridclr,rimclr,axisclr,axislabelclr,titleclr,slideclr DECLARE PUBLIC workLft,workRgt,workBas,workTop,workMidx DECLARE PUBLIC true,false DECLARE DEF quitWithin,infoWithin ! --- help screen array --- DIM info$(1:1) MAT READ info$ DATA "Information" ! ---------- Utility functions --- DECLARE DEF clamp,roundn,e ! --- functions --- DEF dxdt(x,v) LET dxdt= v END DEF DEF dvdt(x,v,t) LET dvdt= - b*v - k*x + a*cos(w*t) END DEF DEF f(t) ! forcing LET f = a*cos(w*t) END DEF DEF sum(x,v,t) LET sum = dvdt(x,v,t) + b*dxdt(x,v) + k*x END DEF DEF g(t) = c*cos(w*t - phi) ! ---------- Graphing plane parameters and methods ---------- LET wwid = 240 LET whgt = 80 LET wvstp= 95 ! --- plane 1 data --- DECLARE PUBLIC w1Lft,w1Rgt,w1Bas,w1Top,w1Midx,w1Midy DECLARE PUBLIC w1fLft,w1fRgt,w1fBas,w1fTop,w1x0,w1y0 DECLARE PUBLIC w1xFirst, w1xSTik, w1xLTik, w1xLabel, w1xGridstep DECLARE PUBLIC w1yFirst, w1ySTik, w1yLTik, w1yLabel, w1yGridstep DECLARE PUBLIC w1wWid,w1wHgt,w1fWid,w1fHgt DECLARE PUBLIC w1fxRatio,w1fyRatio,w1wxRatio,w1wyRatio,w1Aspect DECLARE PUBLIC w1xPiFlag, w1xMult, w1yPiFlag, w1yMult LET w1Flag = 1 LET w1xMult = pi LET w1xPiFlag= 1 LET w1yMult = 1 LET w1yPiFlag= 0 LET w1Lft = workLft+75 ! pixel bounds LET w1Rgt = w1Lft+wwid LET w1Top = workTop+70 LET w1Bas = w1Top+whgt LET w1fLft= 0 ! function bounds LET w1fRgt= 12 LET w1fTop= 2 LET w1fBas= -2 LET w1xAx$= "x" ! axis labels LET w1yAx$= "mx''" LET w1xGridstep= 0 ! horizontal grid intervals LET w1yGridstep= 0 ! vertical grid intervals LET w1xSTik = 1/4 ! horizontal axis Tik marks LET w1xLTik = 1/2 LET w1xLabel= 1 LET w1xFirst= w1fLft LET w1ySTik = 0 ! vertical axis Tik marks LET w1yLTik = 1 LET w1yLabel= 1 LET w1yFirst= w1fBas ! --- Plane 1 methods --- DECLARE DEF w1fncx,w1fncy,w1wndx,w1wndy ! window/function transforms DECLARE DEF w1wWithin CALL w1Variables SUB w1Init CALL w1DrawPlane(1,1,1) ! x axis, y axis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w1Rgt+8,w1y0+3,w1xAx$,axislabelclr) ! axis labels CALL PlotTextCJ(w1x0,w1Top-13,w1yAx$,red) CALL w1KeepGridLayer END SUB ! ------------------------------------------ ! --- plane 2 data --- DECLARE PUBLIC w2Lft,w2Rgt,w2Bas,w2Top,w2Midx,w2Midy DECLARE PUBLIC w2fLft,w2fRgt,w2fBas,w2fTop,w2x0,w2y0 DECLARE PUBLIC w2xFirst, w2xSTik, w2xLTik, w2xLabel, w2xGridstep DECLARE PUBLIC w2yFirst, w2ySTik, w2yLTik, w2yLabel, w2yGridstep DECLARE PUBLIC w2wWid,w2wHgt,w2fWid,w2fHgt DECLARE PUBLIC w2fxRatio,w2fyRatio,w2wxRatio,w2wyRatio,w2Aspect DECLARE PUBLIC w2xPiFlag, w2xMult, w2yPiFlag, w2yMult LET w2Flag = 1 LET w2xPiFlag= 1 LET w2yPiFlag= 0 LET w2xMult = pi LET w2yMult = 1 LET w2Lft = w1Lft ! pixel bounds LET w2Rgt = w1Rgt LET w2Top = w1Bas+wvStp LET w2Bas = w2Top+whgt LET w2fLft= w1fLft ! function bounds * pi LET w2fRgt= w1fRgt LET w2fTop= w1fTop LET w2fBas= w1fBas LET w2xGridstep= 0 ! horizontal grid intervals LET w2yGridstep= 0 ! vertical grid intervals LET w2xAx$= "x" ! axis labels ! LET w2yAx$= "f(x-ct)+g(x+ct)" LET w2yAx$= "bx'" LET w2xSTik = 1/4 ! horizontal axis Tik marks LET w2xLTik = 1/2 LET w2xLabel= 1 LET w2xFirst= w2fLft LET w2ySTik = 0 ! vertical axis Tik marks LET w2yLTik = 1 LET w2yLabel= 1 LET w2yFirst= w2fBas ! --- plane 2 methods --- DECLARE DEF w2fncx, w2fncy, w2wndx, w2wndy ! window/function transforms DECLARE DEF w2wWithin CALL w2Variables LET w2DragMax= w2Wndx(4*pi) SUB w2Init CALL w2DrawPlane(1,1,1) ! x axis, y axis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w2Rgt+8,w2y0+3,w2xAx$,axislabelclr) ! axis labels CALL PlotTextCJ(w2x0,w2Top-13,w2yAx$,green) BOX KEEP w2Lft-5,w2Rgt+5,w2Bas+5,w2Top-5 in w2gridLayer$ CALL w2KeepGridLayer END SUB ! ------------------------------------------ ! --- plane 3 data --- DECLARE PUBLIC w3Lft,w3Rgt,w3Bas,w3Top,w3Midx,w3Midy DECLARE PUBLIC w3fLft,w3fRgt,w3fBas,w3fTop,w3x0,w3y0 DECLARE PUBLIC w3xFirst, w3xSTik, w3xLTik, w3xLabel, w3xGridstep DECLARE PUBLIC w3yFirst, w3ySTik, w3yLTik, w3yLabel, w3yGridstep DECLARE PUBLIC w3wWid,w3wHgt,w3fWid,w3fHgt DECLARE PUBLIC w3fxRatio,w3fyRatio,w3wxRatio,w3wyRatio,w3Aspect DECLARE PUBLIC w3xPiFlag, w3xMult, w3yPiFlag, w3yMult LET w3Flag = 1 ! plane is turned on or off LET w3xPiFlag= 1 LET w3yPiFlag= 0 LET w3xMult = pi LET w3yMult = 1 LET w3Lft = w1Lft ! pixel bounds LET w3Rgt = w1Rgt LET w3Top = w2Bas+wvStp LET w3Bas = w3Top+whgt LET w3fLft= w1fLft ! function bounds LET w3fRgt= w1fRgt LET w3fTop= w1fTop LET w3fBas= w1fBas LET w3xAx$= "x" ! axis labels ! LET w3yAx$= "g(x+ct)" LET w3yAx$= "kx" LET w3xGridstep= 0 ! grid line intervals LET w3yGridstep= 0 LET w3xSTik = 1/4 ! axis Tik marks LET w3xLTik = 1/2 LET w3xLabel= 1 LET w3xFirst= w3fLft LET w3ySTik = 0 LET w3yLTik = 1 LET w3yLabel= 1 LET w3yFirst= w3fBas ! --- plane 3 methods --- DECLARE DEF w3fncx,w3fncy,w3wndx,w3wndy ! window/function transforms DECLARE DEF w3wWithin CALL w3Variables SUB w3Init CALL w3DrawPlane(1,1,1) ! x axis, y axis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w3Rgt+8,w3y0+3,w3xAx$,axislabelclr) ! axis labels CALL PlotTextCJ(w3x0,w3Top-13,w3yAx$,yellow) CALL w3KeepGridLayer CALL w3KeepGraphLayer END SUB ! ------------------------------------------ ! --- plane 4 data --- DECLARE PUBLIC w4Lft,w4Rgt,w4Bas,w4Top,w4Midx,w4Midy DECLARE PUBLIC w4fLft,w4fRgt,w4fBas,w4fTop,w4x0,w4y0 DECLARE PUBLIC w4xFirst, w4xSTik, w4xLTik, w4xLabel, w4xGridstep DECLARE PUBLIC w4yFirst, w4ySTik, w4yLTik, w4yLabel, w4yGridstep DECLARE PUBLIC w4wWid,w4wHgt,w4fWid,w4fHgt DECLARE PUBLIC w4fxRatio,w4fyRatio,w4wxRatio,w4wyRatio,w4Aspect DECLARE PUBLIC w4xPiFlag, w4xMult, w4yPiFlag, w4yMult LET w4Flag = 1 ! plane is turned on or off LET w4xPiFlag= 1 LET w4xMult = pi LET w4yPiFlag= 0 LET w4yMult = 1 LET w4Lft = worklft + 60 ! pixel bounds LET w4Rgt = w4Lft + 360 LET w4Top = worktop + 100 LET w4Bas = w4Top + 360 LET w4fLft= 0 ! function bounds LET w4fRgt= 16 LET w4fTop= 2 LET w4fBas= -2 LET w4xAx$= "t" ! axis labels ! LET w4yAx$= "g(x+ct)" LET w4yAx$= "x" LET w4xGridstep= 0 ! grid line intervals LET w4yGridstep= 0 LET w4xSTik = 1/2 ! axis Tik marks LET w4xLTik = 1 LET w4xLabel= 2 LET w4xFirst= w4fLft LET w4ySTik = 0 LET w4yLTik = 1 LET w4yLabel= 1 LET w4yFirst= w4fBas ! --- plane 3 methods --- DECLARE DEF w4fncx,w4fncy,w4wndx,w4wndy ! window/function transforms DECLARE DEF w4wWithin CALL w4Variables SUB w4Init CALL w4DrawPlane(1,1,1) ! x axis, y axis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w4Rgt+8,w4y0+3,w4xAx$,axislabelclr) ! axis labels CALL PlotTextCJ(w4x0,w4Top-13,w4yAx$,yellow) CALL w4KeepGridLayer CALL w4KeepGraphLayer END SUB ! ----------- horizontal sliders ------------ LET slidewidth= 180 ! --- horizontal slider 1 --- DECLARE DEF h1Within ! window/function transforms DECLARE DEF h1AnimWithin,h1LstpWithin,h1RstpWithin DECLARE PUBLIC h1axis,h1wLft,h1wRgt,h1wBas,h1wTop,h1fLft,h1fRgt DECLARE PUBLIC h1name$,h1form$,h1clr,h1First,h1STik,h1LTik,h1Label DECLARE PUBLIC h1PiAxis,h1Mult,h1fMin,h1fMax LET h1PiAxis= 0 LET h1Mult = 1 LET h1clr = white LET h1name$ = "m" LET h1form$ = "--%.###" LET h1Places= 3 LET h1axis = w1Top + 8 LET h1wLft = w4Rgt + 90 LET h1wRgt = h1wLft + slidewidth LET h1fLft = 0 LET h1fRgt = 4 LET h1STik = 0.5 ! short tick marks LET h1LTik = 1 ! long tick marks LET h1Label= 1 ! labels LET h1First= h1fLft ! first tick mark LET h1Click= 0.5 CALL h1SliderVariables SUB h1Init CALL h1DrawSlider(h1name$,m) END SUB ! --- horizontal slider 2 --- DECLARE DEF h2Within ! window/function transforms DECLARE DEF h2AnimWithin,h2LstpWithin,h2RstpWithin DECLARE PUBLIC h2axis,h2wLft,h2wRgt,h2wBas,h2wTop,h2fLft,h2fRgt DECLARE PUBLIC h2name$,h2form$,h2clr,h2First,h2STik,h2LTik,h2Label DECLARE PUBLIC h2PiAxis,h2Mult,h2fMin,h2fMax LET h2PiAxis= 0 LET h2Mult = 1 LET h2clr = white LET h2name$ = "b" LET h2form$ = "--%.###" LET h2Places= 3 LET h2axis = w4Top + 30 LET h2wLft = h1wLft LET h2wRgt = h2wLft + slidewidth LET h2fLft = 0 LET h2fRgt = 2 LET h2STik = 0.5 ! short tick marks LET h2LTik = 1 ! long tick marks LET h2Label = 1 ! labels LET h2First = h2fLft ! first tick mark LET h2Click = 0.5 CALL h2SliderVariables SUB h2Init CALL h2DrawSlider(h2name$,b) END SUB ! --- horizontal slider 3 --- DECLARE DEF h3Within ! window/function transforms DECLARE DEF h3AnimWithin,h3LstpWithin,h3RstpWithin DECLARE PUBLIC h3axis,h3wLft,h3wRgt,h3wBas,h3wTop,h3fLft,h3fRgt DECLARE PUBLIC h3name$,h3form$,h3clr,h3First,h3STik,h3LTik,h3Label DECLARE PUBLIC h3PiAxis,h3Mult,h3fMin,h3fMax LET h3PiAxis= 0 LET h3Mult = 1 LET h3clr = white LET h3name$ = "k" LET h3form$ = "--%.###" LET h3Places= 3 LET h3axis = h2Axis + 45 LET h3wLft = h1wLft LET h3wRgt = h3wLft + slidewidth LET h3fLft = 0 LET h3fRgt = 4 LET h3STik = 0.5 ! short tick marks LET h3LTik = 1 ! long tick marks LET h3Label= 1 ! labels LET h3First= h3fLft ! first tick mark LET h3Click= 0.5 CALL h3SliderVariables SUB h3Init CALL h3DrawSlider(h3name$,k) END SUB ! --- horizontal slider 4 --- DECLARE DEF h4Within ! window/function transforms DECLARE DEF h4AnimWithin,h4LstpWithin,h4RstpWithin DECLARE PUBLIC h4axis,h4wLft,h4wRgt,h4wBas,h4wTop,h4fLft,h4fRgt DECLARE PUBLIC h4name$,h4form$,h4clr,h4First,h4STik,h4LTik,h4Label DECLARE PUBLIC h4PiAxis,h4Mult,h4fMin,h4fMax LET h4PiAxis= 0 LET h4Mult = 1 LET h4clr = white LET h4name$ = "a" LET h4form$ = "--%.###" LET h4Places= 3 LET h4axis = h3Axis + 45 LET h4wLft = h1wLft LET h4wRgt = h4wLft + slidewidth LET h4fLft = 0 LET h4fRgt = 2 LET h4STik = 0.5 ! short tick marks LET h4LTik = 1 ! long tick marks LET h4Label= 1 ! labels LET h4First= h4fLft ! first tick mark LET h4Click= 0.5 CALL h4SliderVariables SUB h4Init CALL h4DrawSlider(h4name$,a) END SUB ! --- horizontal slider 5 --- DECLARE DEF h5Within ! window/function transforms DECLARE DEF h5AnimWithin,h5LstpWithin,h5RstpWithin DECLARE PUBLIC h5axis,h5wLft,h5wRgt,h5wBas,h5wTop,h5fLft,h5fRgt DECLARE PUBLIC h5name$,h5form$,h5clr,h5First,h5STik,h5LTik,h5Label DECLARE PUBLIC h5PiAxis,h5Mult,h5fMin,h5fMax LET h5PiAxis= 0 LET h5Mult = 1 LET h5clr = white LET h5name$ = "w" LET h5form$ = "--%.###" LET h5Places= 3 LET h5axis = h4Axis + 80 LET h5wLft = h1wLft LET h5wRgt = h5wLft + slidewidth LET h5fLft = 0 LET h5fRgt = 4 LET h5STik = 0.5 ! short tick marks LET h5LTik = 1 ! long tick marks LET h5Label= 1 ! labels LET h5First= h5fLft ! first tick mark LET h5Click= 0.5 CALL h5SliderVariables SUB h5Init CALL h5DrawSlider(h5name$,w) END SUB ! --- horizontal slider 6 --- DECLARE DEF h6Within ! window/function transforms DECLARE DEF h6AnimWithin,h6LstpWithin,h6RstpWithin DECLARE PUBLIC h6axis,h6wLft,h6wRgt,h6wBas,h6wTop,h6fLft,h6fRgt DECLARE PUBLIC h6name$,h6form$,h6clr,h6First,h6STik,h6LTik,h6Label DECLARE PUBLIC h6PiAxis,h6Mult,h6fMin,h6fMax LET h6PiAxis= 0 LET h6Mult = 1 LET h6clr = white LET h6name$ = "A" LET h6form$ = "--%.###" LET h6Places= 3 LET h6axis = h5Axis + 80 LET h6wLft = h1wLft LET h6wRgt = h6wLft + slidewidth LET h6fLft = 0 LET h6fRgt = 2 LET h6STik = 0.5 ! short tick marks LET h6LTik = 1 ! long tick marks LET h6Label= 1 ! labels LET h6First= h6fLft ! first tick mark LET h6Click= 0.5 CALL h6SliderVariables SUB h6Init CALL h6DrawSlider(h6name$,c) END SUB ! --- horizontal slider 7 --- DECLARE DEF h7Within ! window/function transforms DECLARE DEF h7AnimWithin,h7LstpWithin,h7RstpWithin DECLARE PUBLIC h7axis,h7wLft,h7wRgt,h7wBas,h7wTop,h7fLft,h7fRgt DECLARE PUBLIC h7name$,h7form$,h7clr,h7First,h7STik,h7LTik,h7Label DECLARE PUBLIC h7PiAxis,h7Mult,h7fMin,h7fMax LET h7PiAxis= 0 LET h7Mult = 1 LET h7clr = white LET h7name$ = "phi" LET h7form$ = "--%.###" LET h7Places= 3 LET h7axis = h6Axis + 45 LET h7wLft = h1wLft LET h7wRgt = h7wLft + slidewidth LET h7fLft = -4 LET h7fRgt = 4 LET h7STik = 0.5 ! short tick marks LET h7LTik = 1 ! long tick marks LET h7Label= 1 ! labels LET h7First= h7fLft ! first tick mark LET h7Click= 0.5 CALL h7SliderVariables SUB h7Init CALL h7DrawSlider(h7name$,phi) END SUB ! ---------- Text Output Rects ---------- ! --- text rectangle 1 --- LET t1BasLn = w4Top - 50 LET t1Lft = w4Midx - 100 LET t1Rgt = t1Lft+50 LET t1Bas = t1BasLn + 5 LET t1Top = t1BasLn - 15 LET t1Clr = cyan LET t1Label$= "x'' + b x' + k x = " CALL StringWidth(t1Label$,sw) LET t1Eqx = t1Lft + sw LET t1$ = "a cos(wt)" SUB t1Label CALL SetTextFont(1,12,"bold") CALL PlotTextRJ(t1Eqx,t1BasLn,t1Label$,t1Clr) CALL PlotTextLJ(t1Eqx,t1BasLn,t1$,t1Clr) END SUB SUB t1Clear BOX CLEAR t1Lft-2,t1Rgt,t1Bas,t1Top END SUB SUB t1Init CALL t1Label END SUB ! --- text rectangle 2 --- LET t2BasLn = w4Top - 25 LET t2Lft = t1Lft LET t2Rgt = t2Lft+50 LET t2Bas = t2BasLn + 5 LET t2Top = t2BasLn - 15 LET t2Clr = yellow LET t2Label$= "x = " LET t2$ = "A cos(wt - phi)" SUB t2Label CALL SetTextFont(1,12,"bold") CALL PlotTextRJ(t1Eqx,t2BasLn,t2Label$,t2Clr) CALL PlotTextLJ(t1Eqx,t2BasLn,t2$,t2Clr) END SUB SUB t2Clear BOX CLEAR t2Lft-2,t2Rgt,t2Bas,t2Top END SUB SUB t2Init CALL t2Label END SUB ! --- text rectangle 3 --- LET t3BasLn1= t1BasLn LET t3BasLn2= t2BasLn LET t3Lft = h2wLft LET t3Rgt = t3Lft + 50 LET t3Bas = t3BasLn + 5 LET t3Top = t3BasLn - 15 LET t3Clr = cyan LET t31$ = "x(0) = " LET t32$ = "x'(0) = " CALL StringWidth(t32$,sw) LET t3Eqx = t3Lft + sw SUB t3Label CALL SetTextFont(1,12,"bold") CALL PlotTextRJ(t3Eqx,t3BasLn1,t31$,t3Clr) CALL PlotTextRJ(t3Eqx,t3BasLn2,t32$,t3Clr) END SUB SUB t3Value CALL SetTextFont(1,12,"bold") LET txt$= using$("--%.##",pos0) CALL PlotTextLJ(t3Eqx,t3BasLn1,txt$,t3Clr) LET txt$= using$("--%.##",vel0) CALL PlotTextLJ(t3Eqx,t3BasLn2,txt$,t3Clr) END SUB SUB t3Clear BOX CLEAR t3Lft-2,t3Rgt,t3Bas,t3Top END SUB SUB t3Init CALL t3Label CALL t3Value END SUB ! --- default parameters --- ! LET m = 0.5 ! mass is off for now LET b = 0.5 LET k = 2 LET a = 0.5 LET w = 1 LET c = 1 ! A LET phi= -2.5 LET dt = 1/32 LET pos0= 1 LET vel0= 0 ! --- Draw the screen --- CALL InitScreen SUB InitScreen BOX CLEAR worklft,workrgt,workbas,worktop CALL w4Init CALL t1Init CALL t2Init CALL t3Init CALL h2Init CALL h3Init CALL h4Init CALL h5Init CALL h6Init CALL h7Init CALL DrawDE CALL DrawSolution END SUB ! ----------------- Event manager ----------------- DO CALL w1KeepGraphLayer CALL w2KeepGraphLayer CALL w3KeepGraphLayer IF ms<>2 then DO GET MOUSE: mx,my,ms ! IF w1wWithin(mx,my)=true or w2wWithin(mx,my)=true or w3wWithin(mx,my)=true then ! IF oldmx<>mx then ! CALL RollOver ! LET oldmx= mx ! END IF ! ELSE IF ClearFlag=1 then ! CALL RollOverClear ! END IF LOOP until ms=2 END IF IF ClearFlag=1 then CALL RollOverClear END IF IF w2wWithin(mx,my)=true then DO GET MOUSE: mx,my,ms LET mx= clamp(mx,w2Lft,w2DragMax) LET t = w2Fncx(mx) IF t<>oldt then CALL h1Mark(t) CALL h1SliderAction LET oldt= t END IF LOOP until ms=3 ELSE IF h1Within(mx,my)=true then ! h1 time slider CALL w4ShowGridLayer CALL DrawSolution CALL w4KeepGraphLayer IF myoldm then CALL w4ShowGraphLayer CALL DrawDE LET oldm= m END IF END SUB SUB h2MouseClick CALL h2GetClickVal(ms,h2Click,b) CALL h2SliderAction END SUB SUB h2MouseDrag DO CALL h2GetDragVal(ms,h2Places,b) CALL h2SliderAction LOOP until ms=3 END SUB SUB h2SliderAction IF b<>oldb then CALL w4ShowGraphLayer CALL DrawDE LET oldb= b END IF END SUB SUB h3MouseClick CALL h3GetClickVal(ms,h3Click,k) CALL h3SliderAction END SUB SUB h3MouseDrag DO CALL h3GetDragVal(ms,h3Places,k) CALL h3SliderAction LOOP until ms=3 END SUB SUB h3SliderAction IF k<>oldk then CALL w4ShowGraphLayer CALL DrawDE LET oldk= k END IF END SUB SUB h4MouseClick CALL h4GetClickVal(ms,h4Click,a) CALL h4SliderAction END SUB SUB h4MouseDrag DO CALL h4GetDragVal(ms,h4Places,a) CALL h4SliderAction LOOP until ms=3 END SUB SUB h4SliderAction IF a<>olda then CALL w4ShowGraphLayer CALL DrawDE LET olda= a END IF END SUB SUB h5MouseClick CALL h5GetClickVal(ms,h5Click,w) CALL h5SliderAction END SUB SUB h5MouseDrag DO CALL h5GetDragVal(ms,h5Places,w) CALL h5SliderAction LOOP until ms=3 END SUB SUB h5SliderAction IF w<>oldw then CALL w4ShowGridLayer CALL DrawSolution CALL DrawDE LET oldw= w END IF END SUB SUB h6MouseClick CALL h6GetClickVal(ms,h6Click,c) CALL h6SliderAction END SUB SUB h6MouseDrag DO CALL h6GetDragVal(ms,h6Places,c) CALL h6SliderAction LOOP until ms=3 END SUB SUB h6SliderAction IF c<>oldc then CALL w4ShowGraphLayer CALL DrawSolution LET oldc= c END IF END SUB SUB h7MouseClick CALL h7GetClickVal(ms,h7Click,phi) CALL h7SliderAction END SUB SUB h7MouseDrag DO CALL h7GetDragVal(ms,h7Places,phi) CALL h7SliderAction LOOP until ms=3 END SUB SUB h7SliderAction IF phi<>oldphi then CALL w4ShowGraphLayer CALL DrawSolution LET oldphi= phi END IF END SUB ! --- ! --- Tool specific drawing and typesetting routines SUB Animate CALL DrawGraphs3 LET t1= t FOR t= t1 to h1fMax step h1AnimStep LET t= roundn(t,h1AnimStep) CALL DrawGraphs3 CALL h1Mark(t) GET MOUSE: mx,my,ms IF ms=2 then CALL h1AnimStopButtonUp(ms) EXIT FOR END IF NEXT t CALL h1StopButtonClear END SUB SUB DrawGraphs3 ! SET COLOR cyan ! CALL w1ShowGridLayer ! FOR wx= w1lft to w1rgt ! LET t = w1Fncx(wx) ! LET y = f(t) ! LET wy= w1Wndy(y) ! PLOT wx,wy; ! NEXT wx ! PLOT ! ! SET COLOR green ! CALL w2ShowGridLayer ! FOR wx= w2lft to w2rgt ! LET t = w2Fncx(wx) ! LET y = fd1(t) ! LET wy= w2Wndy(y) ! PLOT wx,wy; ! NEXT wx ! PLOT ! ! SET COLOR yellow ! CALL w3ShowGridLayer ! FOR wx= w3lft to w3rgt ! LET t = w3Fncx(wx) ! LET y = fd2(t) ! LET wy= w3Wndy(y) ! PLOT wx,wy; ! NEXT wx ! PLOT END SUB SUB DrawDE ! CALL DrawForcing LET t = 0 LET x = pos0 LET v = vel0 SET COLOR cyan DO ! LET y = sum(x,v,t) LET wy= w4Wndy(x) LET wx= w4Wndx(t) IF wy>w4Top and wy=w4fRgt*pi then EXIT DO LOOP PLOT END SUB SUB RungeKutta4(x,v,t) LET dx1= dxdt(x,v) LET dv1= dvdt(x,v,t) LET x1 = x + .5*dx1*dt LET v1 = v + .5*dv1*dt LET t1 = t + .5*dt LET dx2= dxdt(x1,v1) LET dv2= dvdt(x1,v1,t1) LET x2 = x + .5*dx2*dt LET v2 = v + .5*dv2*dt LET t2 = t + .5*dt LET dx3= dxdt(x2,v2) LET dv3= dvdt(x2,v2,t2) LET x3 = x + dx3*dt LET v3 = v + dv3*dt LET t3 = t + dt LET dx4= dxdt(x3,v3) LET dv4= dvdt(x3,v3,t3) LET dv = (dv1 + 2*dv2 + 2*dv3 + dv4) / 6 LET dx = (dx1 + 2*dx2 + 2*dx3 + dx4) / 6 LET v = v + dt*dv LET x = x + dt*dx END SUB SUB DrawForcing SET COLOR green FOR wx= w4lft to w4rgt LET t = w4Fncx(wx) LET y = f(t) LET wy= w4Wndy(y) IF wy>w4Top and wyw4Top and wyw4Top and wy