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=GPZ070' /> </object>
' Krueg -- Starfield -- Sept. 2012
Delay
=
60
'Delay for smooth framrate
StarQty
=
80
'Number of stars, Too many and it slows the program
SetupWindow
(
)
CreateStars
(
)
While
(
"True"
)
MoveStars
(
)
RefreshRate
(
)
'Comment out this line to see the jerkiness of the array proccessing
EndWhile
Sub
RefreshRate
While
Clock
.
ElapsedMilliseconds
<
FrameRate
EndWhile
FrameRate
=
Clock
.
ElapsedMilliseconds
+
Delay
EndSub
Sub
MoveStars
For
i
=
1
To
StarQty
StarY
[
i
]
=
StarY
[
i
]
+
StarHeight
[
i
]
*
1.5
If
StarY
[
i
]
>
gh
Then
StarY
[
i
]
=
StarY
[
i
]
-
gh
StarX
[
i
]
=
Math
.
GetRandomNumber
(
gw
-
10
)
+
5
EndIf
Shapes
.
Move
(
Star
[
i
]
,
StarX
[
i
]
,
StarY
[
i
]
)
'Checking which moves smother, Shapes.Move or Shapes.Animate
'Shapes.Animate(Star[i],StarX[i],StarY[i],0)
EndFor
EndSub
Sub
CreateStars
For
i
=
1
To
StarQty
GraphicsWindow
.
PenColor
=
"White"
GraphicsWindow
.
BrushColor
=
"White"
StarWidth
[
i
]
=
Math
.
GetRandomNumber
(
2
)
If
i
<
(
StarQty
*
.9
)
Then
StarHeight
[
i
]
=
Math
.
GetRandomNumber
(
3
)
'Create more small stars than big
Else
StarHeight
[
i
]
=
Math
.
GetRandomNumber
(
4
)
+
4
EndIf
Star
[
i
]
=
Shapes
.
AddEllipse
(
StarWidth
[
i
]
,
StarHeight
[
i
]
)
Shapes
.
SetOpacity
(
Star
[
i
]
,
StarHeight
[
i
]
*
5
+
50
)
StarX
[
i
]
=
Math
.
GetRandomNumber
(
gw
-
10
)
+
5
StarY
[
i
]
=
Math
.
GetRandomNumber
(
gh
)
Shapes
.
Move
(
Star
[
i
]
,
StarX
[
i
]
,
StarY
[
i
]
)
EndFor
EndSub
Sub
SetupWindow
gw
=
800
gh
=
600
GraphicsWindow
.
Top
=
5
GraphicsWindow
.
Left
=
5
GraphicsWindow
.
Width
=
gw
GraphicsWindow
.
Height
=
gh
GraphicsWindow
.
BackgroundColor
=
"Black"
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.