Star Field Simulator

star_rain
Graphical Animated Small Basic Program Gallery
     Star Field Simulator  Microsoft Small Basic
     ‘ Program Listing:   GPZ070
  
  1. 5.      ‘ Krueg – Starfield — Sept. 2012
 
  1. 6.      Delay = 60        ‘Delay for smooth framrate
  2. 7.      StarQty = 80      ‘Number of stars, Too many and it slows the program
  3. 8.      SetupWindow()
  4. 9.      CreateStars()
 
  1. 10.  While (“True”)
  2. 11.  MoveStars()
  3. 12.  RefreshRate()   ‘Comment out this line to see the jerkiness of the array proccessing
  4. 13.  EndWhile
 
  1. 14.  Sub RefreshRate
  2. 15.  While Clock.ElapsedMilliseconds < FrameRate
  3. 16.  EndWhile
  4. 17.  FrameRate = Clock.ElapsedMilliseconds + Delay
  5. 18.  EndSub
 
  1. 19.  Sub MoveStars
  2. 20.  For i = 1 To StarQty
  3. 21.  StarY[i] = StarY[i] + StarHeight[i] * 1.5
  4. 22.  If StarY[i] > gh Then
  5. 23.  StarY[i] = StarY[i] – gh
  6. 24.  StarX[i] = Math.GetRandomNumber(gw – 10) + 5
  7. 25.  EndIf
  8. 26.  Shapes.Move(Star[i],StarX[i],StarY[i])      ‘Checking which moves smother, Shapes.Move or Shapes.Animate
  9. 27.  ‘Shapes.Animate(Star[i],StarX[i],StarY[i],0)
  10. 28.  EndFor
  11. 29.  EndSub
 
  1. 30.  Sub CreateStars
  2. 31.  For i = 1 To StarQty
  3. 32.  GraphicsWindow.PenColor = “White”
  4. 33.  GraphicsWindow.BrushColor = “White”
  5. 34.  StarWidth[i] = Math.GetRandomNumber(2)
  6. 35.  If i < (StarQty * .9) Then
  7. 36.  StarHeight[i] = Math.GetRandomNumber(3)   ‘Create more small stars than big
  8. 37.  Else
  9. 38.  StarHeight[i] = Math.GetRandomNumber(4)+4
  10. 39.  EndIf
  11. 40.  Star[i] = Shapes.AddEllipse(StarWidth[i],StarHeight[i])
  12. 41.  Shapes.SetOpacity(Star[i],StarHeight[i]*5+50)
  13. 42.  StarX[i] = Math.GetRandomNumber(gw – 10) + 5
  14. 43.  StarY[i] = Math.GetRandomNumber(gh)
  15. 44.  Shapes.Move(Star[i],StarX[i],StarY[i])
  16. 45.  EndFor
  17. 46.  EndSub
 
  1. 47.  Sub SetupWindow
  2. 48.  gw = 800
  3. 49.  gh = 600
  4. 50.  GraphicsWindow.Top = 5
  5. 51.  GraphicsWindow.Left = 5
  6. 52.  GraphicsWindow.Width = gw
  7. 53.  GraphicsWindow.Height = gh
  8. 54.  GraphicsWindow.BackgroundColor = “Black”
  9. 55.  EndSub
 
  1. 56.  ‘ Copyright (c) Microsoft Corporation. All rights reserved.

Deja un comentario