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=ZHP577-0' /> </object>
Wid
=
200
DrawHeart
(
)
CalcArea
(
)
Controls
.
TextTyped
=
TextEnter
Sub
DrawHeart
GraphicsWindow
.
Clear
(
)
GraphicsWindow
.
PenWidth
=
0
GraphicsWindow
.
BrushColor
=
"Blue"
Txt
=
Shapes
.
AddText
(
""
)
Shapes
.
Move
(
Txt
,
10
,
10
)
TB
=
Controls
.
AddMultiLineTextBox
(
GraphicsWindow
.
Width
-
170
,
10
)
Controls
.
SetSize
(
TB
,
160
,
22
)
GraphicsWindow
.
BrushColor
=
"Red"
C1
=
Shapes
.
AddEllipse
(
Wid
/
2
,
Wid
/
2
)
C2
=
Shapes
.
AddEllipse
(
Wid
/
2
,
Wid
/
2
)
S1
=
Shapes
.
AddRectangle
(
Wid
/
2
,
Wid
/
2
)
GraphicsWindow
.
BrushColor
=
"White"
C3
=
Shapes
.
AddEllipse
(
Wid
/
2
,
Wid
/
2
)
C4
=
Shapes
.
AddEllipse
(
Wid
/
2
,
Wid
/
2
)
Shapes
.
Move
(
C1
,
GraphicsWindow
.
Width
/
2
-
Wid
/
2
,
GraphicsWindow
.
Height
/
2
-
Wid
/
2
)
Shapes
.
Move
(
C2
,
GraphicsWindow
.
Width
/
2
,
GraphicsWindow
.
Height
/
2
-
Wid
/
2
)
Shapes
.
Move
(
S1
,
GraphicsWindow
.
Width
/
2
-
Wid
/
4
,
GraphicsWindow
.
Height
/
2
-
Wid
/
4
)
Shapes
.
Move
(
C3
,
GraphicsWindow
.
Width
/
2
-
Wid
/
2
,
GraphicsWindow
.
Height
/
2
)
Shapes
.
Move
(
C4
,
GraphicsWindow
.
Width
/
2
,
GraphicsWindow
.
Height
/
2
)
EndSub
Sub
CalcArea
Area
=
Math
.
Round
(
Wid
*
Wid
-
(
2
*
Wid
*
Wid
/
16
)
*
Math
.
Pi
-
3
*
(
(
Wid
/
2
)
*
(
Wid
/
2
)
-
Math
.
Pi
*
(
Wid
/
4
)
*
(
Wid
/
4
)
)
)
Shapes
.
SetText
(
Txt
,
"The area of the heart will be "
+
Area
+
" square pixels."
)
EndSub
Sub
TextEnter
If
Text
.
IsSubText
(
Controls
.
GetTextBoxText
(
TB
)
,
Text
.
GetCharacter
(
10
)
)
Then
Wid
=
Controls
.
GetTextBoxText
(
TB
)
DrawHeart
(
)
CalcArea
(
)
EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.