Microsoft Small Basic

Program Listing:
Embed this in your website
InitWindow()
While 1=1
  InitHands()
  Sound.PlayClick()
  Program.Delay(1000)
EndWhile
Sub InitWindow
  GraphicsWindow.Show()
  GraphicsWindow.Title = "Analog Clock"
  GraphicsWindow.BackgroundColor = "Black"
  GW = GraphicsWindow.Width
  GH = GraphicsWindow.Height
  Radius = 200
  MidX = GW/2
  MidY = GH/2
  GraphicsWindow.BrushColor = "BurlyWood"
  GraphicsWindow.DrawEllipse(MidX-Radius-15,MidY-Radius-5,Radius*2+30,Radius*2+20)
  GraphicsWindow.FillEllipse(MidX-Radius-15,MidY-Radius-5,Radius*2+30,Radius*2+20)
  For Angle = 1 To 180
    X = MidX+(Radius+15)*Math.Cos(Math.GetRadians(Angle))
    Y1 = MidY+Radius*Math.Sin(Math.GetRadians(Angle))+15
    Y2 = MidY+(Radius+15)*Math.Sin(Math.GetRadians(-Angle))+10
    Blue = Math.GetRandomNumber(40)+30
    GraphicsWindow.PenWidth = Math.GetRandomNumber(5)
    GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(Blue+100+Math.GetRandomNumber(10),Blue+60+Math.GetRandomNumber(20),Blue)
    Shapes.AddLine(X,Y1,X,Y2)
  EndFor
  GraphicsWindow.BrushColor = "White"
  For i = 1 To 12
    Radians = Math.GetRadians(-i * 30 + 90)
    ClockNum[i] = Shapes.AddText(i)
    Shapes.Move(ClockNum[i],MidX-4+Radius*Math.Cos(Radians),MidY-4-Radius*Math.Sin(Radians))
  EndFor
EndSub
Sub InitHands
  If Clock.Hour  + Clock.Minute/60 + Clock.Second/3600 <> Hour Then
    Shapes.Remove(HourHand)
    Hour = Clock.Hour + Clock.Minute/60 + Clock.Second/3600
    GraphicsWindow.PenColor = "Black"
    GraphicsWindow.PenWidth = 3
    HourHand = Shapes.AddLine(MidX,MidY,MidX+Radius/2*Math.Cos(Math.GetRadians(Hour*30-90)),MidY+Radius/2*Math.Sin(Math.GetRadians(Hour*30-90)))
  EndIf
  If Clock.Minute <> Minute Then
    Shapes.Remove(MinuteHand)
    Minute = Clock.Minute + Clock.Second/60
    GraphicsWindow.PenColor = "Blue"
    GraphicsWindow.PenWidth = 2
    MinuteHand = Shapes.AddLine(MidX,MidY,MidX+Radius/1.2*Math.Cos(Math.GetRadians(Minute*6-90)),MidY+Radius/1.2*Math.Sin(Math.GetRadians(Minute*6-90)))
  EndIf
  If Clock.Second <> Second Then
    Shapes.Remove(SecondHand)
    Second = Clock.Second
    GraphicsWindow.PenColor = "Red"
    GraphicsWindow.PenWidth = 1
    SecondHand = Shapes.AddLine(MidX,MidY,MidX+Radius*Math.Cos(Math.GetRadians(Second*6-90)),MidY+Radius*Math.Sin(Math.GetRadians(Second*6-90)))
  EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.