' Set up a timer to update the clock every 10th of a second
Timer.Interval = 100
Timer.Tick = OnTick
DrawClockFace()
GraphicsWindow.Show()
' SubRoutines...
'========================================
' Tick routine called every 10th of a second to update the clock display
Sub OnTick
' Clear the current clock hands
GraphicsWindow.BrushColor = bgColor
GraphicsWindow.FillEllipse(12,12,clockSize-25,clockSize-25)
DrawHourHand()
DrawMinuteHand()
DrawSecondHand()
EndSub
'========================================
Sub DrawSecondHand
value = Clock.Second + Clock.Millisecond/1000
period = 60
length = halfSize-15
width = 1
GraphicsWindow.PenColor = secondHandColor
DrawHand()
EndSub
'========================================
Sub DrawMinuteHand
value = Clock.Minute + Clock.Second/60
period = 60
length = 7*(halfSize-15)/8 '-20
width = 2
GraphicsWindow.PenColor = minuteHandColor
DrawHand()
EndSub
'========================================
Sub DrawHourHand
value = Clock.Hour + Clock.Minute/60
period = 12
length = 3*(halfSize-15)/4
width = 3
GraphicsWindow.PenColor = hourHandColor
DrawHand()
EndSub
'========================================
' DrawHand - draws the clock hand based on the values of the following global variables
' value - The value used to calculate the angle of the line
' period - The number that represents a full 360 degree rotation.
' For the minute and second hands this is 60, for the hour hand this is 12
' length - The length of the line to be drawn
' width - The width of the pen used to draw the line
Sub DrawHand
GraphicsWindow.PenWidth = width
angle = Math.Pi*(4*value-period)/(2*period)
tx = halfSize+length*Math.Cos(angle)
ty = halfSize+length*Math.Sin(angle)
GraphicsWindow.DrawLine(halfSize, halfSize, tx, ty)
EndSub
'========================================
' DrawClockFace - draws the tick marks around the clock face.
Sub DrawClockFace
GraphicsWindow.PenColor = clockTickColor
For t = 0 To 29
angle = (Math.Pi*t / 30)
cos = Math.Cos(angle)
sin = Math.Sin(angle)