' mw3lib.bas - jackord@kw.igs.net - revised 13 Mar 08 - Liberty Basic v4.02 ' wave incident (n=1) on a film (n=2) on a substrate (n=1.5) ' Initialize Window nomainwin button#1, "Component", [p1], UL, 20, 10, 80, 20 button#1, "Resultant", [p2], UL, 120, 10, 80, 20 WindowWidth=498 ' Scale 0-480 WindowHeight=278 ' Scale 0-240 UpperLeftX=10: UpperLeftY=10 open "Wave Incident on a Film-covered Dielectric" for graphics_nsb as #1 #1 "trapclose [quit]" [waitHere] wait [p1] kk=1: goto [motion] [p2] kk=2: goto [motion] [motion] #1 "cls ; down ; color black" #1 "line 0 120 480 120 ; line 240 0 240 240 ; line 285 0 285 240" #1 "rule XOR" dim yi(81): dim yr(81): dim ys(81) dim ya(16): dim yb(16): dim yc(16): dim yt(66) dim zi(81): dim zr(81): dim zs(81) dim za(16): dim zb(16): dim zc(16): dim zt(66) pi=4*atn(1): dx=pi/20: dt=dx/2 n1=1: n=2: n2=1.5 a1=60: r1=a1*(n1*n2-n*n)/(n1*n2+n*n) ' Amplitudes t=n/n2*(a1+r1): phase=pi/2 ' and a2=t*(n+n2)/2/n: r2=t-a2 ' phases for i=0 to 320 tt=i*dt for j=0 to 80 yi(j)=120-int(a1*sin(tt+(80-j)*dx)) yr(j)=120-int(r1*sin(tt+(j-80)*dx)) ys(j)=yi(j)+yr(j)-120 next j for j=0 to 15 ya(j)=120-int(a2*sin(tt-2*(j-15)*dx+phase)) yb(j)=120-int(r2*sin(tt+2*(j-15)*dx+phase)) yc(j)=ya(j)+yb(j)-120 next j for j=0 to 65 yt(j)=120-int(t*sin(tt-1.5*j*dx+phase)) next j if kk=1 then #1 "color darkpink" for j=1 to 80 if i>0 then #1 "line "; 3*j-3; " "; zi(j-1); " "; 3*j; " "; zi(j) #1 "line "; 3*j-3; " "; yi(j-1); " "; 3*j; " "; yi(j) next j #1 "color red" for j=1 to 80 if i>0 then #1 "line "; 3*j-3; " "; zr(j-1); " "; 3*j; " "; zr(j) #1 "line "; 3*j-3; " "; yr(j-1); " "; 3*j; " "; yr(j) next j #1 "color yellow" for j=1 to 15 if i>0 then #1 "line "; 240+3*j-3; " "; za(j-1); " "; 240+3*j; " "; za(j) #1 "line "; 240+3*j-3; " "; ya(j-1); " "; 240+3*j; " "; ya(j) next j #1 "color green" for j=1 to 15 if i>0 then #1 "line "; 240+3*j-3; " "; zb(j-1); " "; 240+3*j; " "; zb(j) #1 "line "; 240+3*j-3; " "; yb(j-1); " "; 240+3*j; " "; yb(j) next j else #1 "color blue" for j=1 to 80 if i>0 then #1 "line "; 3*j-3; " "; zs(j-1); " "; 3*j; " "; zs(j) #1 "line "; 3*j-3; " "; ys(j-1); " "; 3*j; " "; ys(j) next j for j=1 to 15 if i>0 then #1 "line "; 240+3*j-3; " "; zc(j-1); " "; 240+3*j; " "; zc(j) #1 "line "; 240+3*j-3; " "; yc(j-1); " "; 240+3*j; " "; yc(j) next j end if #1 "color blue" for j=1 to 65 if i>0 then #1 "line "; 285+3*j-3; " "; zt(j-1); " "; 285+3*j; " "; zt(j) #1 "line "; 285+3*j-3; " "; yt(j-1); " "; 285+3*j; " "; yt(j) next j for j=0 to 80 zi(j)=yi(j): zr(j)=yr(j): zs(j)=ys(j) next j for j=0 to 15 za(j)=ya(j): zb(j)=yb(j): zc(j)=yc(j) next j for j=0 to 65 zt(j)=yt(j) next j next i goto [waitHere] [quit] close #1 end