Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=VWB484' /> </object>
clockXRad
=
200
clockYRad
=
200
InitClockFace
(
)
InitClockHands
(
)
While
"True"
UpdateClockHands
(
)
Program
.
Delay
(
1000
)
EndWhile
Sub
InitClockFace
width
=
GraphicsWindow
.
Width
height
=
GraphicsWindow
.
Height
GraphicsWindow
.
BackgroundColor
=
"Black"
For
g
=
1
To
12
angle
=
Math
.
GetRadians
(
g
*
360
/
12
-
90
)
x
=
width
/
2
+
clockXRad
*
Math
.
Cos
(
angle
)
y
=
height
/
2
+
clockYRad
*
Math
.
Sin
(
angle
)
numer
=
g
denom
=
12
If
Text
.
IsSubText
(
numer
/
6
,
"."
)
=
"False"
Then
denom
=
denom
/
6
numer
=
numer
/
6
EndIf
If
Text
.
IsSubText
(
numer
/
3
,
"."
)
=
"False"
Then
denom
=
denom
/
3
numer
=
numer
/
3
EndIf
If
Text
.
IsSubText
(
numer
/
2
,
"."
)
=
"False"
Then
denom
=
denom
/
2
numer
=
numer
/
2
EndIf
If
Text
.
IsSubText
(
numer
/
2
,
"."
)
=
"False"
Then
denom
=
denom
/
2
numer
=
numer
/
2
EndIf
If
denom
=
1
And
numer
=
1
Then
fraction
=
""
fontsize
=
30
Else
fraction
=
numer
+
"/"
+
denom
+
" "
fontsize
=
12
EndIf
GraphicsWindow
.
FontSize
=
fontsize
GraphicsWindow
.
BrushColor
=
GraphicsWindow
.
GetRandomColor
(
)
txt
=
Shapes
.
AddText
(
fraction
+
"π"
)
Shapes
.
Move
(
txt
,
x
-
(
Text
.
GetLength
(
fraction
)
+
1
)
+
fontsize
/
2
,
y
-
fontsize
)
EndFor
EndSub
Sub
InitClockHands
GraphicsWindow
.
PenColor
=
"Blue"
GraphicsWindow
.
PenWidth
=
1
secondAngle
=
Math
.
GetRadians
(
Clock
.
Second
*
6
-
90
)
secondLength
=
(
(
clockXRad
+
clockYRad
)
/
2
)
/
2
x
[
1
]
=
width
/
2
+
secondLength
*
Math
.
Cos
(
secondAngle
+
Math
.
GetRadians
(
45
)
)
y
[
1
]
=
height
/
2
+
secondLength
*
Math
.
Sin
(
secondAngle
+
Math
.
GetRadians
(
45
)
)
x
[
2
]
=
x
[
1
]
+
secondLength
*
Math
.
Cos
(
secondAngle
+
Math
.
GetRadians
(
-
45
)
)
y
[
2
]
=
y
[
1
]
+
secondLength
*
Math
.
Sin
(
secondAngle
+
Math
.
GetRadians
(
-
45
)
)
secondHand
[
1
]
=
Shapes
.
AddLine
(
width
/
2
,
height
/
2
,
x
[
1
]
,
y
[
1
]
)
secondHand
[
2
]
=
Shapes
.
AddLine
(
x
[
1
]
,
y
[
1
]
,
x
[
2
]
,
y
[
2
]
)
GraphicsWindow
.
PenColor
=
"Red"
GraphicsWindow
.
PenWidth
=
2
minuteAngle
=
Math
.
GetRadians
(
Clock
.
Minute
*
6
-
90
)
minuteLength
=
(
(
clockXRad
+
clockYRad
)
/
2
)
/
3
x
[
1
]
=
width
/
2
+
minuteLength
*
Math
.
Cos
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
y
[
1
]
=
height
/
2
+
minuteLength
*
Math
.
Sin
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
x
[
2
]
=
x
[
1
]
+
minuteLength
*
Math
.
Cos
(
minuteAngle
+
Math
.
GetRadians
(
-
30
)
)
y
[
2
]
=
y
[
1
]
+
minuteLength
*
Math
.
Sin
(
minuteAngle
+
Math
.
GetRadians
(
-
30
)
)
x
[
3
]
=
x
[
2
]
+
minuteLength
*
Math
.
Cos
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
y
[
3
]
=
y
[
2
]
+
minuteLength
*
Math
.
Sin
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
minuteHand
[
1
]
=
Shapes
.
AddLine
(
width
/
2
,
height
/
2
,
x
[
1
]
,
y
[
1
]
)
minuteHand
[
2
]
=
Shapes
.
AddLine
(
x
[
1
]
,
y
[
1
]
,
x
[
2
]
,
y
[
2
]
)
minuteHand
[
3
]
=
Shapes
.
AddLine
(
x
[
2
]
,
y
[
2
]
,
x
[
3
]
,
y
[
3
]
)
GraphicsWindow
.
PenColor
=
"White"
GraphicsWindow
.
PenWidth
=
4
hourAngle
=
Math
.
GetRadians
(
Clock
.
Hour
*
30
-
90
)
hourLength
=
(
(
clockXRad
+
clockYRad
)
/
2
)
/
4
x
[
1
]
=
width
/
2
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
y
[
1
]
=
height
/
2
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
x
[
2
]
=
x
[
1
]
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
y
[
2
]
=
y
[
1
]
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
x
[
3
]
=
x
[
2
]
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
y
[
3
]
=
y
[
2
]
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
x
[
4
]
=
x
[
3
]
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
y
[
4
]
=
y
[
3
]
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
hourHand
[
1
]
=
Shapes
.
AddLine
(
width
/
2
,
height
/
2
,
x
[
1
]
,
y
[
1
]
)
hourHand
[
2
]
=
Shapes
.
AddLine
(
x
[
1
]
,
y
[
1
]
,
x
[
2
]
,
y
[
2
]
)
hourHand
[
3
]
=
Shapes
.
AddLine
(
x
[
2
]
,
y
[
2
]
,
x
[
3
]
,
y
[
3
]
)
hourHand
[
4
]
=
Shapes
.
AddLine
(
x
[
3
]
,
y
[
3
]
,
x
[
4
]
,
y
[
4
]
)
EndSub
Sub
UpdateClockHands
GraphicsWindow
.
PenColor
=
"Blue"
GraphicsWindow
.
PenWidth
=
1
secondAngle
=
Math
.
GetRadians
(
Clock
.
Second
*
6
-
90
)
x
[
1
]
=
width
/
2
+
secondLength
*
Math
.
Cos
(
secondAngle
+
Math
.
GetRadians
(
45
)
)
y
[
1
]
=
height
/
2
+
secondLength
*
Math
.
Sin
(
secondAngle
+
Math
.
GetRadians
(
45
)
)
x
[
2
]
=
x
[
1
]
+
secondLength
*
Math
.
Cos
(
secondAngle
+
Math
.
GetRadians
(
-
45
)
)
y
[
2
]
=
y
[
1
]
+
secondLength
*
Math
.
Sin
(
secondAngle
+
Math
.
GetRadians
(
-
45
)
)
For
i
=
1
To
2
Shapes
.
Remove
(
secondHand
[
i
]
)
EndFor
secondHand
[
1
]
=
Shapes
.
AddLine
(
width
/
2
,
height
/
2
,
x
[
1
]
,
y
[
1
]
)
secondHand
[
2
]
=
Shapes
.
AddLine
(
x
[
1
]
,
y
[
1
]
,
x
[
2
]
,
y
[
2
]
)
GraphicsWindow
.
PenColor
=
"Red"
GraphicsWindow
.
PenWidth
=
2
minuteAngle
=
Math
.
GetRadians
(
Clock
.
Minute
*
6
-
90
)
x
[
1
]
=
width
/
2
+
minuteLength
*
Math
.
Cos
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
y
[
1
]
=
height
/
2
+
minuteLength
*
Math
.
Sin
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
x
[
2
]
=
x
[
1
]
+
minuteLength
*
Math
.
Cos
(
minuteAngle
+
Math
.
GetRadians
(
-
30
)
)
y
[
2
]
=
y
[
1
]
+
minuteLength
*
Math
.
Sin
(
minuteAngle
+
Math
.
GetRadians
(
-
30
)
)
x
[
3
]
=
x
[
2
]
+
minuteLength
*
Math
.
Cos
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
y
[
3
]
=
y
[
2
]
+
minuteLength
*
Math
.
Sin
(
minuteAngle
+
Math
.
GetRadians
(
30
)
)
For
i
=
1
To
3
Shapes
.
Remove
(
minuteHand
[
i
]
)
EndFor
minuteHand
[
1
]
=
Shapes
.
AddLine
(
width
/
2
,
height
/
2
,
x
[
1
]
,
y
[
1
]
)
minuteHand
[
2
]
=
Shapes
.
AddLine
(
x
[
1
]
,
y
[
1
]
,
x
[
2
]
,
y
[
2
]
)
minuteHand
[
3
]
=
Shapes
.
AddLine
(
x
[
2
]
,
y
[
2
]
,
x
[
3
]
,
y
[
3
]
)
GraphicsWindow
.
PenColor
=
"White"
GraphicsWindow
.
PenWidth
=
4
hourAngle
=
Math
.
GetRadians
(
Clock
.
Hour
*
30
-
90
)
x
[
1
]
=
width
/
2
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
y
[
1
]
=
height
/
2
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
x
[
2
]
=
x
[
1
]
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
y
[
2
]
=
y
[
1
]
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
x
[
3
]
=
x
[
2
]
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
y
[
3
]
=
y
[
2
]
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
90
/
4
)
)
x
[
4
]
=
x
[
3
]
+
hourLength
*
Math
.
Cos
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
y
[
4
]
=
y
[
3
]
+
hourLength
*
Math
.
Sin
(
hourAngle
+
Math
.
GetRadians
(
-
90
/
4
)
)
For
i
=
1
To
4
Shapes
.
Remove
(
hourHand
[
i
]
)
EndFor
hourHand
[
1
]
=
Shapes
.
AddLine
(
width
/
2
,
height
/
2
,
x
[
1
]
,
y
[
1
]
)
hourHand
[
2
]
=
Shapes
.
AddLine
(
x
[
1
]
,
y
[
1
]
,
x
[
2
]
,
y
[
2
]
)
hourHand
[
3
]
=
Shapes
.
AddLine
(
x
[
2
]
,
y
[
2
]
,
x
[
3
]
,
y
[
3
]
)
hourHand
[
4
]
=
Shapes
.
AddLine
(
x
[
3
]
,
y
[
3
]
,
x
[
4
]
,
y
[
4
]
)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.