none
Small Basic Solar System Simulator

    General discussion

  • Just a bunch of coloured filled circles that follow an elliptical path around a yellow filled circle (the sun).

    Does anybody have any ideas on how to improve this? Is there a simple way to alter the draw order, so that outer-planets
    appear 'outer'?

    Currently, sometimes a planet with a small orbit radius can appear to be on top of planets that have a
    larger orbit radius, and it looks really weird. Any ideas are appreciated.

    Geoff.

    Get it at ... http://smalbasic.com/program/?VKP168

    Or enter this code into Small Basic: VKP168

    Here's the source ...

    '----------------------------------------------------------------------------------------------------------------------
    '   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
    '   http://smalbasic.com/program/?VKP168
    '----------------------------------------------------------------------------------------------------------------------

    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

    • Changed type zylascope Monday, November 16, 2009 7:34 AM
    • Changed type zylascope Thursday, November 19, 2009 5:08 AM
    Tuesday, November 10, 2009 7:58 AM

All replies

  • I think I might have an answer for you as to why the planets overlap oddly.

    I hope you don't mind, I took the liberty of updating some of the code. Look it over and let me know what you think.  I think the updated code fixed the overlap problem, but there are still one or two minor issues to tweek. Here, have a look.

    '----------------------------------------------------------------------------------------------------------------------
    '  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
    '  http://smalbasic.com/program/?VKP168
    '
    ' Original modified by Jeremy Bupp - 6/3/2010
    '----------------------------------------------------------------------------------------------------------------------
    
    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=100 '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
      If i > 1 Then
       prevRad = planetRadius[i]
      Else
       prevRad = 30
      EndIf
      
      planetRadius[i] = Math.GetRandomNumber(600)+ 30
      planetAngle[i] = Math.GetRandomNumber(360)
      planetAngleInc[i] = math.GetRandomNumber(3) + 1
      planetSize[i] = Math.GetRandomNumber(90)+10
      planetColor[i] = GraphicsWindow.GetColorFromRGB(Math.GetRandomNumber(255),Math.GetRandomNumber(255),Math.GetRandomNumber(255))
     EndFor
     
    For i = 1 To numOfPlanets - 1
     For z = 1 To numOfPlanets - i
      If planetRadius[z] > planetRadius[z+1] Then
       temp = planetRadius[z]
       planetRadius[z] = planetRadius[z+1]
       planetRadius[z+1] = temp
      EndIf
     EndFor
     
    EndFor
    
      
     far = 1
     near = 0
    
     For loops=1 To 400
      
      For z=1 To numOfPlanets
       'calc planet size based on angle...
       'make planet smaller if between 90-270 degrees
       If planetAngle[z] > 90 And planetAngle[z] < 270 Then
        planetViewSize[z] = math.Round(planetSize[z] * math.Abs(planetAngle[z] - 180) / 100)
        If planetViewSize[z] = 0 Then
         planetViewSize[z] = 1
        EndIf
        orb[z] = far
       EndIf
       
       'make planet bigger if between 270-360 1-90 degrees'
       If planetAngle[z] > 270 And planetAngle[z] <= 360 Then
        planetViewSize[z] = Math.Round(planetSize[z] * (1 +( (planetAngle[z] - 270) / 100)))'
        If planetViewSize[z] = 0 Then
         planetViewSize[z] = 1
        EndIf 
        orb[z] = near
       EndIf
       'make planet bigger if between 1-90 degrees
       If planetAngle[z] > 0 And planetAngle[z] <= 90 Then
        planetViewSize[z]= Math.Round(planetSize[z] * (1 + (90 - planetAngle[z]) / 100))
        If planetViewSize[z] = 0 Then
         planetViewSize[z] = 1
        EndIf
        orb[z] = near
       EndIf
      EndFor
      
      
      'draw planets far planets...
     '  For i = 0 to numOfPlanets - 1
      For newi = numOfPlanets To 1 Step -1 
    '   newi = numOfPlanets - i
    
       If orb[newi] = far then
        GraphicsWindow.BrushColor=planetColor[newi]
        'lx is the x coordinate of the planet.
        lx = x+planetRadius[newi]*Math.Sin(math.GetRadians(planetAngle[newi]))
        'ly is the y coordinate of the planet.
        ly = y+planetRadius[newi]*math.Cos(math.GetRadians(planetAngle[newi]))*.2
        GraphicsWindow.FillEllipse(lx, ly ,planetViewSize[newi],planetViewSize[newi])
       EndIf 
      EndFor
      
      'draw the sun 
      GraphicsWindow.BrushColor="yellow"
      GraphicsWindow.FillEllipse(x,y,80,80)
      
      'draw near planets...
      For i = 1 to numOfPlanets
       
       If orb[i] = near then
        GraphicsWindow.BrushColor=planetColor[i]
        'lx is the x coordinate of the planet.
        lx = x+planetRadius[i]*Math.Sin(math.GetRadians(planetAngle[i]))
        'ly is the y coordinate of the planet.
        ly = y+planetRadius[i]*math.Cos(math.GetRadians(planetAngle[i]))*.2
        GraphicsWindow.FillEllipse(lx, ly ,planetViewSize[i],planetViewSize[i])
       EndIf 
      EndFor
      
      'calc new values...
      For i = 1 To numOfPlanets
    
       planetAngle[i] = planetAngle[i] + planetAngleInc[i]
       If planetAngle[i] < 0 Then
        planetAngle[i] = planetAngle[i] + 360
       EndIf
       If planetAngle[i] > 360 Then
        planetAngle[i] = planetAngle[i] - 360
       EndIf 
      EndFor
      
      Program.Delay(50)
      '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)
      'GraphicsWindow.Clear()
     EndFor
    Endwhile
    Use in good health!

    Saturday, July 3, 2010 6:46 AM