Microsoft Small Basic

Program Listing: VKP168
'----------------------------------------------------------------------------------------------------------------------
' Microtronix - Solar System Simulator for MS Small Basic v0.7
' by Geoff Williams - 4/11/2009 - Freeware
' This graphic demo appears in my music video "Haunted House" at www.youtube.com/zylascope
' www.cdbaby.com/all/zylascope
' plethora at nsw.chariot.net dot au
'----------------------------------------------------------------------------------------------------------------------

GraphicsWindow.Width=1300
GraphicsWindow.Height=750
GraphicsWindow.BackgroundColor="black"
GraphicsWindow.Title="Microtronix - Solar System Simulator"
GraphicsWindow.Show()
x=GraphicsWindow.Width/2
y=GraphicsWindow.Height/2

While (1=1)
numOfPlanets=Math.GetRandomNumber(9)
delay=Math.GetRandomNumber(100)+50
GraphicsWindow.BrushColor="white"
GraphicsWindow.Clear()
GraphicsWindow.DrawText((GraphicsWindow.Width/2)-30,20,numOfPlanets + " planet system.")

'generate planets properties using random values...
For i=1 To numOfPlanets
Array.setvalue ("planetRadius",i,Math.GetRandomNumber(600)+30)
Array.setvalue("planetAngle",i,Math.GetRandomNumber(360))
Array.setvalue("planetAngleInc",i,math.GetRandomNumber(3) + 1)
Array.setvalue("planetSize",i,Math.GetRandomNumber(90)+10)
Array.setvalue("planetColor",i,GraphicsWindow.GetColorFromRGB(Math.GetRandomNumber(255),Math.GetRandomNumber(255),Math.GetRandomNumber(255)))
EndFor

For loops=1 To 400

'draw the sun first before the planets are drawn so it looks like the planets are in front of the sun, when the planet size is big
GraphicsWindow.BrushColor="yellow"
GraphicsWindow.FillEllipse(x,y,80,80)

For z=1 To numOfPlanets
'calc planet size based on angle...
'make planet smaller if between 90-270 degrees
If Array.getvalue("planetAngle",z) > 90 And Array.getvalue("planetAngle",z) < 270 Then
planetsize = math.Round(Array.getvalue("planetSize",z) * math.Abs(Array.getvalue("planetAngle",z) - 180) / 100)
If planetsize = 0 Then
planetsize = 1
EndIf
EndIf
'make planet bigger if between 270-360 1-90 degrees'
If Array.getvalue("planetAngle",z) > 270 And Array.getvalue("planetAngle",z) <= 360 Then
planetsize = Math.Round(Array.getvalue("planetSize",z) * (1 + (Array.getvalue("planetAngle",z) - 270) / 100)) '
If planetsize = 0 Then
planetsize = 1
EndIf
EndIf
'make planet bigger if between 1-90 degrees
If Array.getvalue("planetAngle",z) > 0 And Array.getvalue("planetAngle",z) <= 90 Then
planetsize= Math.Round(Array.getvalue("planetSize",z) * (1 + (90 - Array.getvalue("planetAngle",z)) / 100))
If planetsize = 0 Then
planetsize = 1
EndIf
EndIf

'draw planets...
GraphicsWindow.BrushColor=Array.getvalue("planetColor",z)
GraphicsWindow.FillEllipse(x+Array.getvalue("planetRadius",z)*Math.Sin(math.GetRadians(Array.getvalue("planetAngle",z))),y+Array.getvalue("planetRadius",z)*math.Cos(math.GetRadians(Array.getvalue("planetAngle",z)))*.2,planetsize,planetsize)

'calc new values...
Array.setvalue("planetAngle",z,Array.getvalue("planetAngle",z) + Array.getvalue("planetAngleInc",z))
If Array.getvalue("planetAngle",z) < 0 Then
Array.setvalue("planetAngle",z,Array.getvalue("planetAngle",z) + 360)
EndIf
If Array.getvalue("planetAngle",z) > 360 Then
Array.setvalue("planetAngle",z,Array.getvalue("planetAngle",z) - 360)
EndIf
EndFor

Program.Delay(delay)
'For t=1 to 5000
'delay loop. If I use program.delay(delay) above, then the graphics don't flicker as much
'EndFor

'GraphicsWindow.Clear()
'draw a black filled rectangle over the screen area taken up by the orbiting planets, this flickers less than .Clear()
GraphicsWindow.BrushColor="black"
GraphicsWindow.FillRectangle(0,250,1300,450)
EndFor
Endwhile