Microsoft Small Basic
![](/img/appicon_32.png)
Program Listing: KMX174
gw = 600
gh = gw
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.CanResize = 0
GraphicsWindow.KeyDown = keydown
GraphicsWindow.Title="Analog Clock"
img_relogio = ImageList.LoadImage("http://nickm.hdfree.com.br/relogio.png")
Timer.Interval = 1000
Timer.Tick = update
h_raio = 155
m_raio = 205
s_raio = 245
Sub keydown
last_key = GraphicsWindow.LastKey
If(last_key = "F1")Then
show_debug = 1
EndIf
EndSub
Sub update
GraphicsWindow.Clear()
' Shapes.AddImage(Program.Directory + "\relogio.png")
GraphicsWindow.DrawImage(img_relogio,0,0)
'draw_numbers()
hour = Clock.Hour
minute = Clock.Minute
second = Clock.Second
GraphicsWindow.BrushColor="black"
GraphicsWindow.FontSize = 25
'GraphicsWindow.DrawRectangle(gw/2-80,gh/2+20,160,32)
'time_txt = Shapes.AddText(Clock.Date)
'Shapes.Move(time_txt,gw/2 - 78,gh/2 + 20)
a_second = 360 / 60 * second
angulo = a_second * 0.0174532925199433
sen = Math.Sin(angulo)
cos = Math.Cos(angulo)
cat_o = sen * s_raio
cat_a = cos * s_raio
GraphicsWindow.PenColor= "red"
GraphicsWindow.PenWidth = "3"
GraphicsWindow.DrawLine(gw / 2,gh/2,(gw/2) + cat_o,( gh / 2) - cat_a)
GraphicsWindow.PenWidth = "2"
a_minute = 360 / 60 * minute + (0.1 * second)
GraphicsWindow.PenColor= "black"
angulo = a_minute * 0.0174532925199433
sen = Math.Sin(angulo)
cos = Math.Cos(angulo)
cat_o = sen * m_raio
cat_a = cos * m_raio
GraphicsWindow.PenWidth = "4"
GraphicsWindow.DrawLine(gw / 2,gh/2,(gw/2) + cat_o,( gh / 2) - cat_a)
GraphicsWindow.PenWidth = "2"
If(hour < 12)Then
a_hour = 360 / 12 * hour + (0.5 * minute)
Else
a_hour = 360 / 12 * hour + (0.5 * minute) - 360
EndIf
angulo = a_hour * 0.0174532925199433
sen = Math.Sin(angulo)
cos = Math.Cos(angulo)
cat_o = sen * h_raio
cat_a = cos * h_raio
GraphicsWindow.PenWidth = "5"
GraphicsWindow.DrawLine(gw / 2,gh/2,(gw/2) + cat_o,( gh / 2) - cat_a)
GraphicsWindow.PenWidth = "2"
GraphicsWindow.BrushColor = "black"
GraphicsWindow.FillEllipse(gw/2 - 10,gh/2-10,20,20)
If(show_debug = 1)Then
TextWindow.Left = GraphicsWindow.Left + 620
TextWindow.Top = GraphicsWindow.Top
TextWindow.Clear()
size = 41
TextWindow.Title="Analog Clock : Debug"
TextWindow.WriteLine("+----------------------------------------+")
TextWindow.WriteLine("| Analog Clock - v1.0 - NM Studio - 2010 |")
TextWindow.WriteLine("+----------------------------------------+")
TextWindow.WriteLine("| |")
TextWindow.Write("|Hour : " + Clock.Hour)
TextWindow.CursorLeft=size
TextWindow.WriteLine("|")
TextWindow.Write("|Minutes : " + Clock.Minute)
TextWindow.CursorLeft=size
TextWindow.WriteLine("|")
TextWindow.Write("|Seconds : " + Clock.Second)
TextWindow.CursorLeft=size
TextWindow.WriteLine("|")
TextWindow.WriteLine("| |")
TextWindow.Write("|a_hour : " + a_hour)
TextWindow.CursorLeft=size
TextWindow.WriteLine("|")
TextWindow.Write("|a_minutes: " + a_minute)
TextWindow.CursorLeft=size
TextWindow.WriteLine("|")
TextWindow.Write("|a_seconds: " + a_second)
TextWindow.CursorLeft=size
TextWindow.WriteLine("|")
TextWindow.WriteLine("| |")
TextWindow.WriteLine("+----------------------------------------+")
EndIf
EndSub