Microsoft Small Basic

Program Listing: MNL048
' Hourglass 20140602 WhTurner33
GraphicsWindow.Width=270
GraphicsWindow.Title="Hourglass"
GraphicsWindow.BackgroundColor="lightyellow"
GraphicsWindow.DrawText(10,100,"How many seconds?")
b1=Controls.AddTextBox(50,150)
Controls.AddButton("Start",100,200)
Controls.ButtonClicked=Text
While secs=""
endwhile
GraphicsWindow.Clear()
GraphicsWindow.DrawText(70,30,"Running time = "+secs+ " sec")
tics=1000*secs/80
'' draw glass
GraphicsWindow.DrawLine(100,100,100,200)
GraphicsWindow.DrawLine(100,200,130,230)
GraphicsWindow.DrawLine(130,230,130,250)
GraphicsWindow.DrawLine(130,250,100,280)
GraphicsWindow.DrawLine(100,280,100,380)
GraphicsWindow.DrawLine(170,100,170,200)
GraphicsWindow.DrawLine(170,200,140,230)
GraphicsWindow.DrawLine(140,230,140,250)
GraphicsWindow.DrawLine(140,250,170,280)
GraphicsWindow.DrawLine(170,280,170,380)
x0=100
y0=100
For i=0 To Math.Pi+0.1 Step 0.1 'upper
x=135-35*math.Cos(i)
y=100-35*Math.Sin(i)
GraphicsWindow.DrawLine(x0,y0,x,y)
x0=x
y0=y
EndFor
x0=100
y0=380
For i=0 To Math.Pi+0.1 Step 0.1 'lower
x=135-35*math.Cos(i)
y=380+35*Math.Sin(i)
GraphicsWindow.DrawLine(x0,y0,x,y)
x0=x
y0=y
EndFor
'' fill with sand
GraphicsWindow.PenColor="gold"
For i=150 To 200
GraphicsWindow.DrawLine(101,i,169,i)
EndFor
For i=200 To 230
GraphicsWindow.DrawLine(i-98,i,368-i,i)
endfor
Timer.Interval=tics
Timer.Tick=KD
GraphicsWindow.BrushColor="gold"
drop=Shapes.AddEllipse(8,8)
Shapes.Move(drop,131,226)
Yup=150

Sub KD
If Yup<229 then
Shapes.Move(drop,131,226)
EndIf
Shapes.Animate(drop,131,558-Yup,500)
GraphicsWindow.PenColor="lightyellow"
If Yup<200 Then
GraphicsWindow.DrawLine(101,Yup,169,Yup)
else
GraphicsWindow.DrawLine(Yup-98,Yup,368-Yup,Yup)
EndIf
GraphicsWindow.PenColor="gold"
If Yup<185 then
dx=34*Math.Cos(Math.ArcSin((184-Yup)/34))
GraphicsWindow.DrawLine(135-dx,563-Yup,135+dx,563-Yup)
ElseIf Yup<230 then
GraphicsWindow.DrawLine(101,563-Yup,169,563-Yup)
Else
Sound.PlayChimeAndWait()
Program.End()
endif
Yup=Yup+1
EndSub
Sub Text
secs=Controls.GetTextBoxText(b1)
EndSub