!SineSumBeats: As noted, changing omega resest A to 1 !It would be more natural to have the rollover recorded in multiples of !pi, but drawing the pi might take too much time? !It might be fast enough if I draw it once, and then capture it as !a pattern of graphics memory - sort of like a rubber stamp. !Meanwhile, I was showing the SineSum tool to someone, the most recent linux !compile, and it broke on me: I set the amplitude A to 1/2, then changed the !frequency (I think - maybe the phase, but I think it was omega) and presto, !the amplitude reset itself to 1. !! File: SineSumBeats !! 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 backclr,black,drkgry,drkmid,midgry,litmid,litgry,white PUBLIC 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$ = "Sine Sum Beats" SUB ThisProgram CALL SineSumBeats 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 SineSumBeats 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,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 on beats and resonance" ! ---------- Utility functions --- DECLARE DEF clamp,roundn,e ! --- functions and parameters DEF pi2 = 2*pi DEF f(x) = sin(x) ! fixed wave DEF g(x) = a * sin(w*x - p) ! adjustable wave DEF env(x) IF w>0.5 and w<1.5 then LET env= (1+a) * cos(0.5*((1-w)*x + p)) ! envelope for w near 1 ELSE IF w<0.5 then LET env= a + g(x) ! envelope for w near 1 END IF END DEF ! ---------- Graphing plane parameters and methods ---------- LET wwid = 600 LET whgt = 128 LET frgt = 200 LET orange= 9 ! ------------------------------------------ ! --- 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 w2xPiFlag, w2xMult, w2yPiFlag, w2yMult DECLARE PUBLIC w2wWid, w2fWid, w2wHgt, w2fHgt, w2Aspect LET w2Flag = 1 LET w2xPiFlag= 1 LET w2yPiFlag= 0 LET w2xMult = pi LET w2yMult = 1 LET w2clr = green LET w2Lft = worklft+90 ! pixel window bounds LET w2Rgt = w2Lft+wwid LET w2Top = workTop+40 LET w2Bas = w2Top+whgt LET w2fLft= 0 ! function bounds * pi LET w2fRgt= 60 LET w2fTop= 2 ! function bounds LET w2fBas= -2 LET w2xGridstep= 0 ! horizontal grid intervals LET w2yGridstep= 0 ! vertical grid intervals LET w2xAx$= "t" ! axis labels LET w2yAx$= "f(t) + g(t)" LET w2xSTik = 0 ! horizontal axis Tik marks LET w2xLTik = 2 LET w2xLabel = 10 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 SUB w2InitPlane CALL w2DrawPlane(1,1,1) ! xaxis, yaxis, zeroaxes CALL SetTextFont(1,12,"bold") CALL PlotTextLJ(w2Rgt+8,w2y0+3,w2xAx$,axislabelclr) ! axis labels CALL PlotTextCJ(w2x0,w2Top-12,w2yAx$,w2clr) CALL w2KeepGridLayer END SUB ! --- 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 w1xPiFlag, w1xMult, w1yPiFlag, w1yMult DECLARE PUBLIC w1wWid, w1fWid, w1wHgt, w1fHgt, w1Aspect LET w1Flag = 1 ! pixel window visibility LET w1xPiFlag= 1 ! pi switch for x axis LET w1yPiFlag= 0 ! pi switch for y axis LET w1xMult = pi LET w1yMult = 1 LET w1clr = red LET w3clr = yellow LET w1Lft = workLft+90 ! pixel window bounds LET w1Rgt = w1Lft+wwid LET w1Top = w2Bas + 70 LET w1Bas = w1Top+whgt LET w1fLft= 0 ! function bounds LET w1fRgt= w2fRgt LET w1fTop= 2 LET w1fBas= -2 LET w1xAx$= "t" ! axis labels LET w1yAx$= "f(t) = sin(t)" LET w3yAx$= "g(t) = A sin(wt+phi)" LET w1xGridstep= 0 ! horizontal grid intervals LET w1yGridstep= 0 ! vertical grid intervals LET w1xSTik = 0 ! horizontal axis Tik marks LET w1xLTik = 2 LET w1xLabel= 10 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 w1InitPlane 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 PlotTextRJ(w1x0,w1Top-30,"f(t) = ",red) CALL PlotTextLJ(w1x0,w1Top-30,"sin(t)",red) CALL PlotTextRJ(w1x0,w1Top-12,"g(t) = ",w3Clr) CALL StringWidth("A sin(w",sw) CALL SwapOmega(w1x0,w1Top-12,"A sin(w","w",w3Clr) CALL SwapPhi(w1x0+sw+2,w1Top-12,"t + p)","p",w3Clr) CALL w1KeepGridLayer END SUB ! ----------- horizontal sliders ------------ LET slideWidth= 100 ! --- horizontal slider 1 --- DECLARE PUBLIC h1axis,h1wLft,h1wRgt,h1wBas,h1wTop,h1fLft,h1fRgt DECLARE PUBLIC h1name$,h1form$,h1clr,h1First,h1STik,h1LTik,h1Label DECLARE PUBLIC h1PiAxis,h1Mult,h1fMin,h1fMax DECLARE DEF h1Within ! window/function transforms LET h1PiAxis= 0 LET h1Mult = 1 LET h1clr = white LET h1name$ = "A" LET h1form$ = "%.##" LET h1Places= 2 LET h1axis = workbas - 25 LET h1wLft = w1Lft LET h1wRgt = h1wLft+100 LET h1fLft = 0 LET h1fRgt = 1 LET h1STik = 0.1 ! short tick marks LET h1LTik = 0.5 ! long tick marks LET h1Label= 0.5 ! labels LET h1First= h1fLft ! first tick mark LET h1Click= 1/2 SUB h1InitSlider CALL h1SliderVariables CALL h1DrawSlider(h1name$,a) END SUB ! --- horizontal slider 2 --- DECLARE PUBLIC h2axis,h2wLft,h2wRgt,h2wBas,h2wTop,h2fLft,h2fRgt DECLARE PUBLIC h2name$,h2form$,h2clr,h2First,h2STik,h2LTik,h2Label DECLARE PUBLIC h2PiAxis,h2Mult,h2fMin,h2fMax DECLARE DEF h2Within ! window/function transforms LET h2PiAxis= 0 LET h2Mult = 1 LET h2clr = white LET h2name$ = "" ! omega LET h2form$ = "%.###" LET h2Places= 3 LET h2axis = h1axis - 45 LET h2wLft = w1Lft LET h2wRgt = h2wLft + 600 LET h2fLft = 0 LET h2fRgt = 2 LET h2STik = 0.05 ! short tick marks LET h2LTik = 0.1 ! long tick marks LET h2Label= 0.5 ! labels LET h2First= h2fLft ! first tick mark LET h2Click= 0.05 DECLARE DEF h2LstpWithin , h2RstpWithin DECLARE DEF h2LmoveWithin, h2RmoveWithin LET h2AnimStep= 0.001 LET h2MoveStep= 0.002 SUB h2InitSlider CALL h2SliderVariables CALL h2DrawSlider(h2name$,w) CALL SwapOmega(h2wLft-16,h2wbas-2,"w","w",white) CALL h2MoveButtons END SUB ! --- horizontal slider 3 --- DECLARE DEF h3Within ! window/function transforms 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= 1 LET h3Mult = pi LET h3clr = white LET h3name$ = "" LET h3form$ = "%.##" LET h3Places= 2 LET h3axis = h1axis LET h3wLft = h1wRgt + 100 LET h3wRgt = h3wLft + 100 LET h3fLft = 0 LET h3fRgt = 2 LET h3STik = 0 ! short tick marks LET h3LTik = 0.5 ! long tick marks LET h3Label= 1 ! labels LET h3First= h3fLft ! first tick mark LET h3Click= pi/2 SUB h3InitSlider CALL h3SliderVariables CALL h3DrawSlider(h3name$,p) CALL SwapPhi(h3wLft-15,h3wbas-2,"p","p",white) END SUB ! ---------- Text Output Rects ---------- ! --- text rectangle 1 --- LET t1BasLn = w1Bas + 40 LET t1Lft = w1Lft LET t1Rgt = t1Lft + 150 LET t1Bas = t1BasLn + 5 LET t1Top = t1BasLn - 15 LET t1Label$= "_[tone] = " LET t1Eqx = t1lft + 55 LET t1vBasLn= t1BasLn + 20 LET t1vBas = t1vBasLn + 5 LET t1vTop = t1vBasLn - 15 LET t1clr = green SUB t1Label CALL SetTextFont(1,9,"bold") CALL StringWidth("tone",sw9) CALL SetTextFont(1,12,"bold") CALL StringWidth(" = ",sw12) LET sw= sw9+sw12 CALL SuperSubScriptRJ(t1Eqx,t1BasLn,t1Label$,t1Clr) CALL DrawLam(t1Eqx-sw-10,t1BasLn,t1Clr) CALL PlotTextRJ(t1Eqx,t1vBasLn,"= ",t1Clr) END SUB SUB t1Set IF (a+w)<>0 then LET t1$= "(4/(w_[n]+w))" CALL SuperSubScriptOmegaLJ(t1Eqx,t1BasLn,t1$,"w",t1Clr) LET t1$= "(4/(wn+w))" CALL StringWidth(t1$,sw) BOX SHOW t1pi$ at t1Eqx+sw+4,t1BasLn ELSE END IF CALL t1vSet END SUB SUB t1vSet CALL t1vClear IF (a+w)<>0 then LET t1$= trim$(using$("---%.##",4/(a+w))) CALL PlotTextLJ(t1Eqx,t1vBasLn,t1$,t1Clr) CALL StringWidth(t1$,sw) BOX SHOW t1pi$ at t1Eqx+sw+4,t1vBasLn ELSE CALL SwapInf(t1Eqx+2,t1vBasLn,"8","8",t1Clr) END IF END SUB SUB t1Clear BOX CLEAR t1Lft-2,t1Rgt,t1Bas,t1Top END SUB SUB t1vClear BOX CLEAR t1Eqx-2,t1Rgt,t1vBas,t1vTop END SUB SUB t1Init CALL t1Label CALL t1Set END SUB ! --- text rectangle 2 --- LET t2BasLn = t1BasLn LET t2Lft = w2Rgt - 165 LET t2Rgt = w2Rgt + 20 LET t2Bas = t2BasLn + 5 LET t2Top = t2BasLn - 15 LET t2Label$= "_[packet] = " LET t2Eqx = t2Lft + 75 LET t2vBasLn= t2BasLn + 20 LET t2vBas = t2vBasLn + 5 LET t2vTop = t2vBasLn - 15 LET t2Clr = cyan SUB t2Label CALL SetTextFont(1,9,"bold") CALL StringWidth("packet",sw9) CALL SetTextFont(1,12,"bold") CALL StringWidth(" = ",sw12) LET sw= sw9+sw12 CALL SuperSubScriptRJ(t2Eqx,t2BasLn,t2Label$,t2Clr) CALL DrawLam(t2Eqx-sw-10,t2BasLn,t2Clr) CALL PlotTextRJ(t2Eqx,t2vBasLn,"= ",t2Clr) END SUB SUB t2Set LOCAL z$ IF a-w<>0 then CALL SetTextFont(1,12,"bold") LET t2$= "(2/|w_[n]-w|)" CALL SuperSubScriptOmegaLJ(t2Eqx,t2BasLn,t2$,"w",t2Clr) LET t2$= "(2/|wn-w|)" CALL StringWidth(t2$,sw) BOX SHOW t2pi$ at t2Eqx+sw+4,t2BasLn ELSE END IF CALL t2vSet END SUB SUB t2vSet CALL t2vClear CALL SetTextFont(1,12,"bold") LET t2a= 1 IF t2a-w<>0 then LET t2$= trim$(using$("----%.##",2/abs(t2a-w))) CALL PlotTextLJ(t2Eqx,t2vBasLn,t2$,t2Clr) CALL StringWidth(t2$,sw) BOX SHOW t2pi$ at t2Eqx+sw+4,t2vBasLn ELSE CALL SwapInf(t2Eqx+2,t2vBasLn,"8","8",t2Clr) END IF END SUB SUB t2vClear BOX CLEAR t2Eqx-2,t2Rgt,t2vBas,t2vTop END SUB SUB t2Init CALL t2Label CALL t2Set END SUB ! --- Rollover parameters and cleanup --- LET rolft = w2Lft - 25 LET rorgt = w2Rgt + 40 LET robasln= w2Top - 27 LET robas = robasln+ 5 LET rotop = robasln-10 SUB ClearRollText BOX CLEAR rolft,rorgt,robas,rotop END SUB SUB ClearRollover CALL w1ShowGraphLayer CALL w2ShowGraphLayer CALL ClearRollText LET clearflag= 0 END SUB ! --- Buttons --- LET elft= w2Rgt - 78 LET ergt= elft + 78 LET etop= w2Bas + 25 LET ebas= etop + 18 SUB EnvButton(state) LET EnvBtnFlag= state IF state=1 then CALL SetTextFont(1,12,"Bold") CALL DrawButton(elft,ergt,ebas,etop,5,"Envelope") ELSE BOX CLEAR elft,ergt,ebas,etop LET envelopeFlag= 0 END IF END SUB ! --- Default Parameters --- LET a,olda= 1 LET w,oldw= 1.05 LET p,oldp= 0 CALL InitPi(worklft+1,worktop+10,green,t1pi$) CALL InitPi(worklft+1,worktop+10,cyan,t2pi$) CALL InitPi(worklft+1,worktop+10,white,w1pi$) LET envelopeFlag= 0 IF a=1 then LET EnvBtnFlag= 1 ! --- Draw the screen --- CALL InitScreen SUB InitScreen BOX CLEAR worklft,workrgt,workbas,worktop CALL w1InitPlane CALL w2InitPlane CALL h1InitSlider CALL h2InitSlider CALL h3InitSlider CALL EnvButton(EnvBtnFlag) CALL w1DrawGraph CALL w1KeepGridLayer CALL DrawGraphs(1) CALL t1Init CALL t2Init END SUB ! ----------------- Event manager ----------------- DO LET clearflag= 0 LET oldmx = -99999 CALL SetTextFont(1,12,"Bold") DO GET MOUSE: mx,my,ms IF mx>w1Lft and mxw2Top and myh2fLft and wh2fLft and weLft and mxeTop and myoldmx then LET oldmx= mx SET COLOR litgry CALL w1ShowGraphLayer PLOT mx,w1Bas-1; mx,w1Top+1 CALL w2ShowGraphLayer PLOT mx,w2Bas-1; mx,w2Top+1 CALL ClearRollText LET x = w1Fncx(mx)/pi LET n$= trim$(using$("---%.##",x)) CALL StringWidth(n$,sw) LET nrgt= mx+sw/2+2 CALL PlotTextCJ(mx,robasln,n$,white) BOX SHOW w1pi$ at nrgt,robasln LET clearflag= 1 END IF END SUB ! --- h1 slider events --- SUB h1MouseClick CALL h1GetClickVal(ms,h1Click,a) CALL h1MouseAction(1) END SUB SUB h1MouseDrag DO CALL h1GetDragVal(ms,h1Places,a) CALL h1MouseAction(2) LOOP until ms=3 CALL DrawGraphs(1) END SUB SUB h1MouseAction(drawstep) IF a<>olda then IF a=1 and olda<>1 then CALL EnvButton(1) ELSE IF a<>1 and olda=1 then CALL EnvButton(0) END IF LET olda= a CALL DrawGraphs(drawstep) END IF END SUB ! --- h2 slider events --- SUB h2MouseClick CALL h2GetClickVal(ms,h2Click,w) CALL h2MouseAction(1) END SUB SUB h2MouseDrag DO CALL h2GetDragVal(ms,h2Places,w) CALL h2MouseAction(2) LOOP until ms=3 CALL DrawGraphs(1) END SUB SUB h2MouseAction(drawstep) IF w<>oldw then CALL DrawGraphs(drawstep) CALL t1vSet CALL t2vSet LET oldw= w END IF END SUB ! --- h3 slider events SUB h3MouseClick CALL h3GetClickVal(ms,h3Click,p) CALL h3MouseAction(1) END SUB SUB h3MouseDrag DO CALL h3GetDragVal(ms,h3Places,p) CALL h3MouseAction(2) LOOP until ms=3 CALL DrawGraphs(1) END SUB SUB h3MouseAction(drawstep) IF p<>oldp then LET oldp= p CALL DrawGraphs(drawstep) END IF END SUB ! --- graph drawing routines --- SUB w1DrawGraph ! addend waves CALL w1ShowGridLayer SET COLOR w1clr FOR wx= w1lft to w1rgt LET x = w1Fncx(wx) LET y1= f(x) LET wy= w1Wndy(y1) PLOT wx,wy; NEXT wx PLOT CALL w1KeepGraphLayer END SUB SUB DrawEnvelope(estp) IF w<>1 then SET COLOR cyan FOR wx= w2lft to w2rgt step estp LET x = w2Fncx(wx) LET y1= env(x) LET wy= w2Wndy(y1) PLOT wx,wy IF w>0.5 and w<1.5 then LET y1= -y1 LET wy= w2Wndy(y1) PLOT wx,wy ELSE IF w<0.5 then LET y1= y1-2*a LET wy= w2Wndy(y1) PLOT wx,wy END IF NEXT wx PLOT END IF END SUB SUB DrawGraphs(stp) ! stp>1 means animation CALL w2ShowGridLayer ! sum curve (beats- upper plane) IF envelopeFlag=1 then CALL DrawEnvelope(stp/2) SET COLOR w2clr FOR wx= w2lft to w2rgt step stp LET x = w2Fncx(wx) LET y1= g(x)+f(x) LET wy= w2Wndy(y1) PLOT wx,wy; NEXT wx PLOT CALL w1ShowGridLayer ! addend curve (lower plane) SET COLOR w3clr FOR wx= w1lft to w1rgt step stp LET x = w1Fncx(wx) LET y2= g(x) LET wy= w1Wndy(y2) PLOT wx,wy; NEXT wx PLOT IF stp=1 then ! keep for rollover CALL w1KeepGraphLayer CALL w2KeepGraphLayer END IF END SUB END SUB ! --- end of Sine sum beats code -------------------