Microsoft Small Basic

Program Listing: VSC500-0
' Cat's Eyes Clock 0.1
' published as VSC500-0
' Copyright (c) 2012 Nonki Takahashi. All rights reserved.
'
' History :
' 0.2 2012/07/11 Changed from draw to shapes.
' 0.1 2012/07/10 Created from Alarm 0.1.
'
itx = 33
ity = 55
sBGColor = "White"
sFGColor = "Black"
sTitle = "Cat's Eyes Clock 0.2"
GraphicsWindow.Title = sTitle
GraphicsWindow.BrushColor = sFGColor
GraphicsWindow.BackgroundColor = sBGColor
left = 340
top = 60
width = 200
height = 300
InitClock()
DrawCat()
bTicked = "False"
Timer.Interval = 1000
Timer.Tick = OnTick
While "True"
Program.Delay(500)
If bTicked Then
DrawClock()
DrawIrises()
bTicked = "False"
If Math.Remainder(iSec, 5) = 0 Then
Blink()
EndIf
EndIf
EndWhile

Sub Blink
Shapes.HideShape(oLIris)
Shapes.HideShape(oRIris)
Shapes.HideShape(oLEye)
Shapes.HideShape(oREye)
Program.Delay(100)
Shapes.ShowShape(oLIris)
Shapes.ShowShape(oRIris)
Shapes.ShowShape(oLEye)
Shapes.ShowShape(oREye)
EndSub
Sub DrawArc
' param cx, cy - center
' param r - radius
' param a1, a2 - start and end angle [degree]
' param pw - pen width
' param pc - pen color
GraphicsWindow.BrushColor = pc
For a = a1 To a2
x = cx + r * Math.Cos(a * Math.Pi / 180) - pw / 2
y = cy + r * Math.Sin(a * Math.Pi / 180) - pw / 2
GraphicsWindow.FillEllipse(x, y, pw, pw)
EndFor
EndSub

Sub DrawCat
' param left, top - left top position of cat
' param width, height - size of cat
' return lex, ley - left eye center
' return rex, rey - right eye center
' return eh - eye height

' Calculate each eye position
lex = left + width * 0.33
ley = top + height * 0.35
rex = left + width * 0.67
rey = ley
ew = width * 0.3
eh = height * 0.16
' Draw body
GraphicsWindow.BrushColor = "#5e5e5e"
x = left + width * 0.25
y = top + height * 0.8
w = width * 0.5
h = height * 0.2
GraphicsWindow.FillEllipse(x, y, w, h)
x1 = x
y1 = y + h / 2
x2 = x + w
y2 = y1
x3 = (x1 + x2) / 2
y3 = ley
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3)
' Draw tail
pc = "#5e5e5e"
pw = width * 0.1
cx = left + width * 0.65
cy = top + height * 0.72
r = width * 0.3
a1 = 0
a2 = 90
DrawArc()
' Draw ears
GraphicsWindow.BrushColor = "DimGray" ' #696969
x1 = lex - ew / 2
y1 = ley
x2 = lex + ew / 2
y2 = ley
x3 = (x1 + x2) / 2
y3 = top
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3) ' left
GraphicsWindow.BrushColor = "LightGray"
x1 = x1 + width * 0.05
x2 = x2 - width * 0.05
y3 = top + height * 0.08
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3) ' left
GraphicsWindow.BrushColor = "DimGray"
x1 = rex - ew / 2
y1 = rey
x2 = rex + ew / 2
y2 = rey
x3 = (x1 + x2) / 2
y3 = top
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3) ' right
GraphicsWindow.BrushColor = "LightGray"
x1 = x1 + width * 0.05
x2 = x2 - width * 0.05
y3 = top + height * 0.08
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3) ' right
' Draw face
GraphicsWindow.BrushColor = "DimGray"
x = left + width * 0.15
y = top + height * 0.15
w = width * 0.7
h = height * 0.4
GraphicsWindow.FillEllipse(x, y, w, h)
' Draw wiskers
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "DimGray"
x1 = lex
y1 = ley + eh / 2
r = width * 0.3
For a = 165 To 195 Step 15
x2 = x1 + r * Math.Cos(a / 180 * Math.Pi)
y2 = y1 + r * Math.Sin(a / 180 * Math.Pi)
GraphicsWindow.DrawLine(x1, y1, x2, y2)
EndFor
x1 = rex
y1 = rey + eh / 2
For a = -15 To 15 Step 15
x2 = x1 + r * Math.Cos(a / 180 * Math.Pi)
y2 = y1 + r * Math.Sin(a / 180 * Math.Pi)
GraphicsWindow.DrawLine(x1, y1, x2, y2)
EndFor
' Draw closed eyes
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(lex - ew / 2, ley - 1, ew, 2) ' left
GraphicsWindow.FillRectangle(rex - ew / 2, rey - 1, ew, 2) ' right
' Draw eyes
GraphicsWindow.BrushColor = "White"
GraphicsWindow.PenColor = "White"
oLEye = Shapes.AddEllipse(ew, eh) ' left
Shapes.Move(oLEye, lex - ew / 2, ley - eh / 2)
oREye = Shapes.AddEllipse(ew, eh) ' right
Shapes.Move(oREye, rex - ew / 2, rey - eh / 2)
' Draw Irises
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.PenColor = "Black"
oLIris = Shapes.AddEllipse(eh, eh) ' left
Shapes.Move(oLIris, lex - eh / 2, ley - eh / 2)
oRIris = Shapes.AddEllipse(eh, eh) ' right
Shapes.Move(oRIris, rex - eh / 2, rey - eh / 2)
EndSub

Sub DrawIrises
' param lex, ley - left eye center
' param rex, rey - right eye center
' param eh - eye height
' param iHour - hour
If (0 <= iHour And iHour <= 6) Or (18 <= iHour And iHour <= 23) Then
ew = eh * 0.8
Else
hr = iHour
If (6 < hr And hr < 12) Then
hr = 24 - hr
EndIf
hr = hr - 12 + 0.5
ew = eh * 0.8 * hr / 12.5
EndIf
Shapes.Zoom(oLIris, ew / eh, 1)
Shapes.Move(oLIris, lex - eh / 2, ley - eh / 2)
Shapes.Zoom(oRIris, ew / eh, 1)
Shapes.Move(oRIris, rex - eh / 2, rey - eh / 2)
EndSub

Sub InitClock
' return oClock - text object for clock
GraphicsWindow.FontSize = ity
GraphicsWindow.BrushColor = sFGColor
oClock = Shapes.AddText("")
Shapes.Move(oClock, itx * 1.4, ity * 3)
EndSub

Sub DrawClock
' param iHour - hour
' param iMin - minute
' param iSec - second
If iHour < 10 Then
sTime = Text.Append("0", iHour) + ":"
Else
sTime = iHour + ":"
EndIf
If iMin < 10 Then
sTime = sTime + "0" + iMin + ":"
Else
sTime = sTime + iMin + ":"
EndIf
If iSec < 10 Then
sTime = sTime + "0" + iSec
Else
sTime = sTime + iSec
EndIf
Shapes.SetText(oClock, sTime)
EndSub

Sub OnTick
iHour = Clock.Hour
iMin = Clock.Minute
iSec = Clock.Second
bTicked = "True"
EndSub