Microsoft Small Basic

Program Listing:
Embed this in your website
' Challenge of the month September 2013 real Pendulum By NaochanON FWR293-0
' T=2*Pi*Sqrt(L/g)
' W=2*Pi/T
' X0=L*sin(Sinit)
' X(t)= X0*cos(S) = X0*cos(W*t) =X0*cos(2*Pi*t/T)
' Y(t)=Sqrt(L^2-X(t)^2)
' a= -g/L*X(t) Acceleration

GUI()
GraphicsWindow.MouseDown=Ondown
GraphicsWindow.MouseMove=onmove
GraphicsWindow.MouseUp=OnUp

While "true"
  While catch="Release"
    dt=(clock.ElapsedMilliseconds-t0)/1000
    getrad()
    move_Circle()
    Program.Delay(20)
  endwhile
endwhile

Sub OnUp
  catch="Release"
  X0=L*math.sin(Sinit)
  Y0=math.SquareRoot(L*L-X0*X0)
  t0=clock.ElapsedMilliseconds
  AC0=  grav/L*X0
EndSub

Sub getrad
  Xt=X0*math.cos(2*math.Pi*dt/T)
  Yt=math.SquareRoot(L*L-Xt*Xt)
  rad= Math.ArcTan(Xt/Yt)
endsub

Sub Onmove
  If mouse.IsLeftButtonDown and catch="True" then
    MX2= GraphicsWindow.MouseX
    MY2= GraphicsWindow.MouseY
    Sinit= 3.14/2+Math.ArcTan((100-MY2)/((400+2)-MX2))
    X0=L*math.sin(Sinit)
    Y0=math.SquareRoot(L*L-X0*X0)
    getrad()
    move_Circle()
  EndIf
EndSub

Sub move_Circle
  CX=Xt+(400+2)-50
  CY= Yt+100-50
  Shapes.Move(circle,CX,CY)
  Shapes.Rotate(line,math.GetDegrees(-rad))
  Shapes.Move(arrow,shapes.GetLeft(circle)+20,Shapes.GetTop(circle)+20)
  ACc= -grav/L*Xt
  Shapes.Zoom(arrow,math.Abs(ACC/AC0),1)
  Shapes.Rotate(arrow,180-math.Ceiling(ACC/AC0)*180)
  mess="Time= "+math.Floor(dt*10)/10
  Shapes.SetText(msg,mess)
EndSub

sub Ondown
  MX= GraphicsWindow.MouseX
  MY= GraphicsWindow.MouseY
  If Math.Abs(MX-(shapes.GetLeft(circle)+50))<50 And Math.Abs(MX-(shapes.Gettop(circle)+50))<50 Then
    catch="True"
  endif
EndSub

Sub GUI
  GraphicsWindow.BackgroundColor="Black"
  GraphicsWindow.Width=800
  GraphicsWindow.Height=600
  GraphicsWindow.PenColor="darkGreen"
  GraphicsWindow.BrushColor="DarkGreen"
  GraphicsWindow.PenWidth=4
  line= Shapes.AddLine(0,0,0,600)     ' Length= 600/2=300
  Shapes.Move(Line,400,-200)
  '------------------------------------------------------------------
  GraphicsWindow.BrushColor="Black"
  GraphicsWindow.PenColor="Black"
  mask=shapes.AddRectangle(800,100)
  '------------------------------------------------------------------
  GraphicsWindow.PenColor="Yellow"
  GraphicsWindow.BrushColor="Yellow"
  circle= Shapes.AddEllipse(100,100)  ' radius=100/2=50
  Shapes.Move(circle,400+2-50,100+300)
  msg= Shapes.AddText(" ")
  Shapes.Move(msg,120,20)
  '------------------------------------------------------------------
  GraphicsWindow.PenColor="Red"
  GraphicsWindow.BrushColor="Red"
  GraphicsWindow.FontSize=60
  arrow= Shapes.AddText(Text.GetCharacter(2*16*16*16+7*16*16+10*16+0))  '27A0
  Shapes.Rotate(arrow,180)
  Shapes.Move(arrow,shapes.GetLeft(circle)+20,Shapes.GetTop(circle)+20)
  '------------------------------------------------------------------
  L=600/2+100/2
  L0=L/1000
  grav=9.8
  T=2*math.pi*math.SquareRoot(L0/grav)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.