' fosblib.bas - jackord@kw.igs.net - revised 6 Apr 05 - Liberty Basic v4.01" ' Initialize Window nomainwin button#1, "Plot", [plt], UL, 5, 5, 40, 20 WindowWidth=390 ' pixel scale 0-380 WindowHeight=269 ' pixel scale 0-240 UpperLeftX=100: UpperLeftY=100 open "Driven Oscillator" for graphics_nsb as #1 #1 "trapclose [quit]" dim xs(121): dim xa(8): dim ya(8): dim yb(8) pi=4*atn(1) for i=0 to 120 ' Define spring xs(i)=10+int(8*sin(i*pi/10)) next i xa(0)=9: xa(1)=6: xa(2)=10: xa(3)=14 ' Define arrow xa(4)=11: xa(5)=11: xa(6)=9: xa(7)=xa(0) #1 "cls ; down ; color black ; line 20 120 375 120" ' Plot axis n=355: m=2: k=8: f=6: w=(k/m)^.5: dt=7.1*pi/n #1 "rule xor ; backcolor red ; color red" #1 "place 10 120 ; circlefilled 7 ; circle 7" ' Draw mass #1 "color black ; place 10 240" for i=1 to 120 ' Draw spring #1 "goto "; xs(i); " "; 240-i next i [waitHere] wait [plt] #1 "cls ; down ; color black ; line 20 120 375 120" #1 "rule xor ; backcolor red ; color red" #1 "place 10 120 ; circlefilled 7 ; circle 7" ' Draw mass #1 "color black ; place 10 240" for i=1 to 120 ' Draw spring #1 "goto "; xs(i); " "; 240-i next i x=0: v=0 : y1=120: z1=120: xo=x tt=time$("ms") for i=1 to n ' Feynman algorithm ff=f*sin(i*w*dt): x=x+v*dt: v=v+(ff-k*x)/m*dt d=int(5*ff): y2=120-d: z2=120-int(5*x) #1 "color blue ; line "; 19+i; " "; y1; " "; 20+i; " "; y2 ' F(t) #1 "color red ; line "; 19+i; " "; z1; " "; 20+i; " "; z2 ' x(t) #1 "color black" for j=1 to 120 ' Draw spring s1=240-int((120+5*xo)*(j-1)/120): s2=240-int((120+5*xo)*j/120) #1 "line "; xs(j-1); " "; s1; " "; xs(j); " "; s2 t1=240-int((120+5*x)*(j-1)/120): t2=240-int((120+5*x)*j/120) #1 "line "; xs(j-1); " "; t1; " "; xs(j); " "; t2 next j #1 "color red ; place 10 "; z1: #1 "circlefilled 7 ; circle 7" #1 "place 10 "; z2: #1 "circlefilled 7 ; circle 7 ; color blue" if abs(d)>3 then ' Draw arrow ya(0)=z2-d+4*abs(d)/d: ya(1)=ya(0): ya(3)=ya(0): ya(4)=ya(0) ya(2)=z2-d: ya(5)=z2: ya(6)=ya(5): ya(7)=ya(0) for k=1 to 7 if i>1 then #1 "line "; xa(k-1); " "; yb(k-1); " "; xa(k); " "; yb(k) end if #1 "line "; xa(k-1); " "; ya(k-1); " "; xa(k); " "; ya(k) next k for k=0 to 7 yb(k)=ya(k) next k end if xo=x: y1=y2: z1=z2 scan: #1 "discard" next i tt=time$("ms")-tt #1 "color black ; backcolor white" #1 "place 5 40": #1 "\Run time(ms)="; tt goto [waitHere] [quit] close #1 end