' mw2lib.bas - jackord@kw.igs.net - revised 13 Mar 08 - Liberty Basic v4.02 ' wave striking an interface between n[left]=1 and n[right]=2-.2i ' 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 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" #1 "rule XOR" dim yi(81): dim yr(81): dim yt(81): dim ys(81) dim zi(81): dim zr(81): dim zt(81): dim zs(81) pi=4*atn(1): dx=pi/20: dt=dx/2 n=2: k=.2: a=60 r=a*((1-n)*(1-n)+k*k)^.5/((1+n)*(1+n)+k*k)^.5 ' Amplitudes theta=atn((2*k)/(1-n*n-k*k))+pi ' and t=2*a/((1+n)*(1+n)+k*k)^.5 ' phases phi=atn(k/(1+n)) for i=0 to 320 tt=i*dt for j=0 to 80 yi(j)=120-int(a*sin(tt+(80-j)*dx)) yr(j)=120-int(r*sin(tt+(j-80)*dx+theta)) yt(j)=120-int(t*exp(0-k*j*dx)*sin(tt-2*j*dx+phi)) ys(j)=yi(j)+yr(j)-120 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 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 end if #1 "color blue" for j=1 to 80 if i>0 then #1 "line "; 240+3*j-3; " "; zt(j-1); " "; 240+3*j; " "; zt(j) #1 "line "; 240+3*j-3; " "; yt(j-1); " "; 240+3*j; " "; yt(j) next j for j=0 to 80 zi(j)=yi(j): zr(j)=yr(j): zt(j)=yt(j): zs(j)=ys(j) next j next i goto [waitHere] [quit] close #1 end