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=LBD742-4' /> </object>
' Pendulum Clock 0.24
' Copyright (c) 2013 Nonki Takahashi. All rights reserved.
'
' History:
' 0.24 2013/02/15 Bug fixed. (LBD742-4)
' 0.2 2013/02/14 Changed for Silverlight. (LBD742-0)
' 0.1 2013/02/14 Created. (LBD742)
' 0.0 2013/02/14 14:37:20 Shapes generated by Shapes 1.5
'
GraphicsWindow
.
Title
=
"Pendulum Clock 0.24"
gw
=
569
gh
=
426
GraphicsWindow
.
Width
=
gw
GraphicsWindow
.
Height
=
gh
color
=
GraphicsWindow
.
GetPixel
(
0
,
0
)
If
Text
.
GetLength
(
color
)
>
7
Then
silverlight
=
"True"
Else
silverlight
=
"False"
EndIf
' initialize shapes
Shapes_Init
(
)
cx
=
shX
+
92
cy
=
shY
+
92
' add shapes
scale
=
1
Shapes_Add
(
)
GraphicsWindow
.
FontName
=
"Consolas"
GraphicsWindow
.
FontSize
=
12
GraphicsWindow
.
BrushColor
=
"Black"
Timer
.
Interval
=
250
Timer
.
Tick
=
OnTick
Sub
OnTick
tick
=
Math
.
Remainder
(
tick
+
1
,
8
)
If
tick
=
0
Then
If
Clock
.
Minute
=
0
And
Clock
.
Second
=
0
Then
times
=
Math
.
Remainder
(
Clock
.
Hour
,
12
)
EndIf
ShowClock
(
)
If
times
>
0
Then
Sound
.
PlayBellRing
(
)
times
=
times
-
1
Else
Sound
.
PlayClick
(
)
EndIf
angle
=
10
ElseIf
tick
=
1
Then
angle
=
9
ElseIf
tick
=
2
Then
angle
=
7
ElseIf
tick
=
3
Then
angle
=
-
2
ElseIf
tick
=
4
Then
If
Clock
.
Minute
=
0
And
Clock
.
Second
=
0
Then
times
=
Math
.
Remainder
(
Clock
.
Hour
,
12
)
EndIf
ShowClock
(
)
If
times
>
0
Then
Sound
.
PlayBellRing
(
)
times
=
times
-
1
Else
Sound
.
PlayClick
(
)
EndIf
angle
=
-
10
ElseIf
tick
=
5
Then
angle
=
-
9
ElseIf
tick
=
6
Then
angle
=
-
7
ElseIf
tick
=
7
Then
angle
=
2
EndIf
ShowPendulum
(
)
EndSub
Sub
ShowClock
r
=
15
angle
=
Math
.
Remainder
(
Clock
.
Hour
,
12
)
*
30
+
Clock
.
Minute
/
2
x
=
r
*
Math
.
Sin
(
Math
.
GetRadians
(
angle
)
)
+
cx
y
=
-
r
*
Math
.
Cos
(
Math
.
GetRadians
(
angle
)
)
+
cy
Shapes
.
Move
(
shape
[
38
]
[
"obj"
]
,
x
-
2
,
y
-
r
)
' hour hand
Shapes
.
Rotate
(
shape
[
38
]
[
"obj"
]
,
angle
)
r
=
30
angle
=
Clock
.
Minute
*
6
+
Clock
.
Second
/
10
x
=
r
*
Math
.
Sin
(
Math
.
GetRadians
(
angle
)
)
+
cx
y
=
-
r
*
Math
.
Cos
(
Math
.
GetRadians
(
angle
)
)
+
cy
Shapes
.
Move
(
shape
[
39
]
[
"obj"
]
,
x
-
1
,
y
-
r
)
' minute hand
Shapes
.
Rotate
(
shape
[
39
]
[
"obj"
]
,
angle
)
angle
=
Clock
.
Second
*
6
x
=
r
*
Math
.
Sin
(
Math
.
GetRadians
(
angle
)
)
+
cx
y
=
-
r
*
Math
.
Cos
(
Math
.
GetRadians
(
angle
)
)
+
cy
Shapes
.
Move
(
shape
[
40
]
[
"obj"
]
,
x
,
y
-
r
)
' second hand
Shapes
.
Rotate
(
shape
[
40
]
[
"obj"
]
,
angle
)
EndSub
Sub
ShowPendulum
' param angle
r
=
56
x
=
-
r
*
Math
.
Sin
(
Math
.
GetRadians
(
angle
)
)
+
cx
y
=
r
*
Math
.
Cos
(
Math
.
GetRadians
(
angle
)
)
+
shY
+
170
Shapes
.
Move
(
shape
[
4
]
[
"obj"
]
,
x
-
4
,
y
-
60
)
' pendulum rod
Shapes
.
Rotate
(
shape
[
4
]
[
"obj"
]
,
angle
)
r
=
81
x
=
-
r
*
Math
.
Sin
(
Math
.
GetRadians
(
angle
)
)
+
cx
y
=
r
*
Math
.
Cos
(
Math
.
GetRadians
(
angle
)
)
+
shY
+
170
Shapes
.
Move
(
shape
[
5
]
[
"obj"
]
,
x
-
29
,
y
-
29
)
' pendulum weight
EndSub
Sub
Shapes_Init
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX
=
200
' x offset
shY
=
55
' y offset
shape
=
""
shape
[
1
]
=
"func=tri;x=28;y=287;x1=64;y1=0;x2=0;y2=39;x3=129;y3=39;angle=180;bc=#1A0500;pw=0;"
shape
[
2
]
=
"func=rect;x=28;y=157;width=129;height=130;bc=#000000;pw=0;"
shape
[
3
]
=
"func=tri;x=56;y=287;x1=36;y1=0;x2=0;y2=20;x3=73;y3=20;angle=180;bc=#000000;pw=0;"
shape
[
4
]
=
"func=rect;x=87;y=165;width=9;height=121;bc=#BF8D3D;pc=#E6B870;pw=2;"
' pendulum rod
shape
[
5
]
=
"func=ell;x=62;y=222;width=59;height=59;bc=#BF8D3D;pc=#E6B870;pw=4;"
' pendulum weight
shape
[
6
]
=
"func=rect;x=28;y=157;width=28;height=130;bc=#1A0500;pw=0;"
shape
[
7
]
=
"func=rect;x=129;y=157;width=28;height=130;bc=#1A0500;pw=0;"
shape
[
8
]
=
"func=line;x=59;y=190;x1=0;y1=0;x2=0;y2=91;pc=#E6B870;pw=2;"
shape
[
9
]
=
"func=line;x=126;y=190;x1=0;y1=0;x2=0;y2=91;pc=#E6B870;pw=2;"
shape
[
10
]
=
"func=line;x=59;y=190;x1=0;y1=0;x2=67;y2=0;pc=#E6B870;pw=2;"
shape
[
11
]
=
"func=line;x=59;y=280;x1=0;y1=0;x2=34;y2=19;pc=#E6B870;pw=2;"
shape
[
12
]
=
"func=line;x=92;y=280;x1=0;y1=19;x2=34;y2=0;pc=#E6B870;pw=2;"
shape
[
13
]
=
"func=tri;x=54;y=92;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;bc=#1A0500;pw=0;"
shape
[
14
]
=
"func=tri;x=22;y=78;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;angle=45;bc=#1A0500;pw=0;"
shape
[
15
]
=
"func=tri;x=8;y=46;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;angle=90;bc=#1A0500;pw=0;"
shape
[
16
]
=
"func=tri;x=22;y=13;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;angle=135;bc=#1A0500;pw=0;"
shape
[
17
]
=
"func=tri;x=54;y=0;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;angle=180;bc=#1A0500;pw=0;"
shape
[
18
]
=
"func=tri;x=87;y=13;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;angle=225;bc=#1A0500;pw=0;"
shape
[
19
]
=
"func=tri;x=100;y=45;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;angle=270;bc=#1A0500;pw=0;"
shape
[
20
]
=
"func=tri;x=87;y=78;x1=38;y1=0;x2=0;y2=92;x3=77;y3=92;angle=315;bc=#1A0500;pw=0;"
shape
[
21
]
=
"func=ell;x=11;y=11;width=163;height=163;bc=#DFA549;pc=#E6B870;pw=4;"
shape
[
22
]
=
"func=ell;x=22;y=22;width=141;height=141;bc=#FFFFFF;pc=#E6B870;pw=4;"
' dial plate
shape
[
23
]
=
"func=text;x=113;y=34;text= I;angle=30;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
24
]
=
"func=text;x=132;y=53;text=II;angle=60;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
25
]
=
"func=text;x=137;y=80;text=III;angle=90;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
26
]
=
"func=text;x=126;y=107;text=IIII;angle=120;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
27
]
=
"func=text;x=116;y=127;text=V;angle=150;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
28
]
=
"func=text;x=86;y=134;text=VI;angle=180;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
29
]
=
"func=text;x=56;y=127;text=VII;angle=210;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
30
]
=
"func=text;x=33;y=108;text=VIII;angle=240;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
31
]
=
"func=text;x=32;y=81;text=IX;angle=270;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
32
]
=
"func=text;x=39;y=54;text= X;angle=300;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
33
]
=
"func=text;x=58;y=34;text=XI;angle=330;bc=#000000;fs=18;fn=Coulier New;"
' hour numeral
shape
[
34
]
=
"func=text;x=82;y=26;text=XII;bc=#000000;fs=20;fn=Coulier New;"
' hour numeral
shape
[
35
]
=
"func=text;x=76;y=60;text=NONKI;bc=#000000;fs=10;fn=Coulier New;"
shape
[
36
]
=
"func=ell;x=67;y=110;width=9;height=9;bc=#C0C0C0;pc=#000000;pw=2;"
shape
[
37
]
=
"func=ell;x=107;y=110;width=9;height=9;bc=#C0C0C0;pc=#000000;pw=2;"
shape
[
38
]
=
"func=rect;x=90;y=92;width=5;height=30;bc=#333333;pw=0;"
' hour hand
shape
[
39
]
=
"func=rect;x=91;y=92;width=3;height=60;bc=#000000;pw=0;"
' minute hand
shape
[
40
]
=
"func=rect;x=92;y=92;width=1;height=60;bc=#000000;pw=0;"
' second hand
shape
[
41
]
=
"func=ell;x=86;y=86;width=13;height=13;bc=#DFA549;pc=#E6B870;pw=4;"
' center
EndSub
Sub
Shapes_Add
' Shapes | Add shapes as shapes data
' param shape - array of shapes
' param scale - to zoom
' return nShapes - number of shapes
' return shAngle - current angle of shapes
Stack
.
PushValue
(
"local"
,
i
)
nShapes
=
Array
.
GetItemCount
(
shape
)
index
=
Array
.
GetAllIndices
(
shape
)
s
=
scale
For
j
=
1
To
nShapes
i
=
index
[
j
]
GraphicsWindow
.
PenWidth
=
shape
[
i
]
[
"pw"
]
*
s
If
shape
[
i
]
[
"pw"
]
>
0
Then
GraphicsWindow
.
PenColor
=
shape
[
i
]
[
"pc"
]
EndIf
If
Text
.
IsSubText
(
"rect|ell|tri|text"
,
shape
[
i
]
[
"func"
]
)
Then
GraphicsWindow
.
BrushColor
=
shape
[
i
]
[
"bc"
]
EndIf
If
shape
[
i
]
[
"func"
]
=
"rect"
Then
shape
[
i
]
[
"obj"
]
=
Shapes
.
AddRectangle
(
shape
[
i
]
[
"width"
]
*
s
,
shape
[
i
]
[
"height"
]
*
s
)
ElseIf
shape
[
i
]
[
"func"
]
=
"ell"
Then
shape
[
i
]
[
"obj"
]
=
Shapes
.
AddEllipse
(
shape
[
i
]
[
"width"
]
*
s
,
shape
[
i
]
[
"height"
]
*
s
)
ElseIf
shape
[
i
]
[
"func"
]
=
"tri"
Then
shape
[
i
]
[
"obj"
]
=
Shapes
.
AddTriangle
(
shape
[
i
]
[
"x1"
]
*
s
,
shape
[
i
]
[
"y1"
]
*
s
,
shape
[
i
]
[
"x2"
]
*
s
,
shape
[
i
]
[
"y2"
]
*
s
,
shape
[
i
]
[
"x3"
]
*
s
,
shape
[
i
]
[
"y3"
]
*
s
)
ElseIf
shape
[
i
]
[
"func"
]
=
"line"
Then
shape
[
i
]
[
"obj"
]
=
Shapes
.
AddLine
(
shape
[
i
]
[
"x1"
]
*
s
,
shape
[
i
]
[
"y1"
]
*
s
,
shape
[
i
]
[
"x2"
]
*
s
,
shape
[
i
]
[
"y2"
]
*
s
)
ElseIf
shape
[
i
]
[
"func"
]
=
"text"
Then
If
silverlight
Then
fs
=
Math
.
Floor
(
shape
[
i
]
[
"fs"
]
*
0.9
)
Else
fs
=
shape
[
i
]
[
"fs"
]
EndIf
GraphicsWindow
.
FontSize
=
fs
*
s
GraphicsWindow
.
FontName
=
shape
[
i
]
[
"fn"
]
shape
[
i
]
[
"obj"
]
=
Shapes
.
AddText
(
shape
[
i
]
[
"text"
]
)
EndIf
If
silverlight
And
shape
[
i
]
[
"func"
]
=
"tri"
Then
alpha
=
Math
.
GetRadians
(
shape
[
i
]
[
"angle"
]
)
x1
=
-
Math
.
Floor
(
shape
[
i
]
[
"x3"
]
/
2
)
y1
=
-
Math
.
Floor
(
shape
[
i
]
[
"y3"
]
/
2
)
ox
=
shape
[
i
]
[
"x"
]
-
x1
oy
=
shape
[
i
]
[
"y"
]
-
y1
r
=
Math
.
SquareRoot
(
x1
*
x1
+
y1
*
y1
)
x
=
x1
*
Math
.
Cos
(
alpha
)
-
y1
*
Math
.
Sin
(
alpha
)
+
ox
y
=
x1
*
Math
.
Sin
(
alpha
)
+
y1
*
Math
.
Cos
(
alpha
)
+
oy
Shapes
.
Move
(
shape
[
i
]
[
"obj"
]
,
shX
+
x
*
s
,
shY
+
y
*
s
)
Else
Shapes
.
Move
(
shape
[
i
]
[
"obj"
]
,
shX
+
shape
[
i
]
[
"x"
]
*
s
,
shY
+
shape
[
i
]
[
"y"
]
*
s
)
EndIf
If
Text
.
IsSubText
(
"rect|ell|tri|text"
,
shape
[
i
]
[
"func"
]
)
And
shape
[
i
]
[
"angle"
]
<>
0
Then
Shapes
.
Rotate
(
shape
[
i
]
[
"obj"
]
,
shape
[
i
]
[
"angle"
]
)
EndIf
shape
[
i
]
[
"rx"
]
=
shape
[
i
]
[
"x"
]
shape
[
i
]
[
"ry"
]
=
shape
[
i
]
[
"y"
]
EndFor
shAngle
=
0
i
=
Stack
.
PopValue
(
"local"
)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.