Advertisement
MrMusAddict

NMS in Excel

Aug 16th, 2016
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub playGod()
  2.  
  3. Dim rd As Integer 'radius
  4. Dim rdMax As Integer 'max planetary radius
  5. Dim rdMin As Integer 'min planetary radius
  6.  
  7. Dim x As Integer 'vertical location of planetary body's center
  8. Dim y As Integer 'horizontal location of planetary body's center
  9.  
  10. Dim locMax As Integer 'max distance from 0,0 to spawn planet
  11. Dim locMin As Integer 'min distance from 0,0 to spawn planet
  12.  
  13. Dim rndRGB As Integer 'random value used to determine which color to alter (r, g, or b)
  14.  
  15. Dim r As Integer 'red color value
  16. Dim g As Integer 'green color value
  17. Dim b As Integer 'blue color value
  18.  
  19. Dim sr As Integer 'red color value for the sun
  20. Dim sg As Integer 'green coor value for the sun
  21.  
  22. Dim dimVal As Double 'value used to determine how much pixel should be dimmed (night-time side of a planet)
  23.  
  24. Dim bodies As Integer 'number of planets to generate
  25.  
  26. Dim max As Integer 'max RGB value
  27. Dim min As Integer 'min RGB value
  28.  
  29. Dim smax As Integer 'sun max RGB value
  30. Dim smin As Integer 'sun min rgb value
  31.  
  32. Cells.Clear 'remove everything
  33.  
  34. 'make 4 planets
  35. bodies = 4
  36.  
  37. 'each between radius 10 and 75
  38. rdMax = 75
  39. rdMin = 10
  40.  
  41. 'centered somewhere between (0,0) and (300,300)
  42. locMax = 300
  43. locMin = 0
  44.  
  45. 'RGB values can range from 0-255
  46. max = 255
  47. min = 0
  48.  
  49. 'Red / Green values for the sun can range from 205-255
  50. smin = 205
  51. smax = 255
  52.  
  53. ''start our RGB values at something random between 100 and 150 (floored to a multiple of 5)
  54. r = (((Math.Rnd * 50 + 0.5) \ 5) * 5) + 100
  55. g = (((Math.Rnd * 50 + 0.5) \ 5) * 5) + 100
  56. b = (((Math.Rnd * 50 + 0.5) \ 5) * 5) + 100
  57.  
  58. ''generate space (i.e. make all cells black)
  59. Cells.Interior.Color = RGB(0, 0, 0)
  60.  
  61. ''throw in some stars (i.e. set 1000 random cells to white)
  62. For i = 1 To 1000
  63.     Cells((Math.Rnd * 300) \ 1, (Math.Rnd * 900) \ 1).Interior.Color = RGB(255, 255, 255)
  64. Next i
  65.  
  66. ''make the planets
  67. For Z = 1 To bodies
  68.    
  69.     'generate a random radius and location
  70.    rd = ((Math.Rnd * (rdMax - rdMin)) \ 1) + rdMin
  71.     x = ((Math.Rnd * (locMax - locMin)) \ 1) + locMin + rd
  72.     y = ((Math.Rnd * (locMax - locMin)) \ 1) + locMin + rd
  73.    
  74.     'do stuff within the center (x,y) +/- radiu
  75.    'I add 1 to the lower bound, and subtract 1 from the upper bound to remove what I like to call planetary nipples.
  76.    For i = x - rd + 1 To x + rd - 1
  77.         For j = y - rd + 1 To y + rd - 1
  78.        
  79.             'determine how much we have to dim a cell, to make a shadow
  80.            '"j" is the current horizontal location that we're drawing
  81.            '"(y - rd + 1)" is our lower bound
  82.            '"(y + rd - 1)" is out upperbound
  83.            'if the current cell is 50, lowerbound is 40, upper is 80:
  84.            '(50-40)/(80-40)  ->  10/40  -> 0.25
  85.            dimVal = (j - (y - rd + 1)) / ((y + rd - 1) - (y - rd + 1))
  86.            
  87.             'dimVal should never be 0, but this is here in case you wanted to add more shadow
  88.            '(i.e. subtract something from the above dimVal equation)
  89.            If dimVal <= 0 Then
  90.                 dimVal = 0
  91.             End If
  92.            
  93.             'check if our current current cell is within the defined circle
  94.            'using the Standard Form equation for the circle
  95.            If ((i - x) ^ 2) + ((j - y) ^ 2) <= rd ^ 2 Then
  96.            
  97.                 'generate a random number between 1 and 6
  98.                rndRGB = (Math.Rnd * 6 + 0.5) \ 1
  99.                
  100.                 '1: increase red by 5
  101.                '2: decrease red by 5
  102.                '3: increase green by 5
  103.                '4: decrease green by 5
  104.                '5: increase blue by 5
  105.                '6: decrease blue by 5
  106.                If rndRGB = 1 Then
  107.                     r = r + 5
  108.                 End If
  109.                
  110.                 If rndRGB = 2 Then
  111.                     r = r - 5
  112.                 End If
  113.                
  114.                 If rndRGB = 3 Then
  115.                     g = g + 5
  116.                 End If
  117.                
  118.                 If rndRGB = 4 Then
  119.                     g = g - 5
  120.                 End If
  121.                
  122.                 If rndRGB = 5 Then
  123.                     b = b + 5
  124.                 End If
  125.                
  126.                 If rndRGB = 6 Then
  127.                     b = b - 5
  128.                 End If
  129.                
  130.                
  131.                 'make sure the values for RGB do
  132.                'not go outside the defined bounds
  133.                If r > max Then
  134.                     r = max
  135.                 End If
  136.                
  137.                 If r < min Then
  138.                     r = min
  139.                 End If
  140.                
  141.                 If g > max Then
  142.                     g = max
  143.                 End If
  144.                
  145.                 If g < min Then
  146.                     g = min
  147.                 End If
  148.                                        
  149.                 If b > max Then
  150.                     b = max
  151.                 End If
  152.                
  153.                 If b < min Then
  154.                     b = min
  155.                 End If
  156.                
  157.                 'set the current cells background color to RGB,
  158.                'multiplied by the amount we need to dim,
  159.                'floored to make sure the value stays an integer
  160.                Cells(i, j).Interior.Color = RGB((r * dimVal) \ 1, (g * dimVal) \ 1, (b * dimVal) \ 1)
  161.             End If
  162.         Next j
  163.     Next i
  164. Next Z
  165.  
  166.  
  167. '''set sun's properties'''
  168.  
  169. 'radius 250, centered (150,900)
  170. '(keeping in mind x is our vertical value in this)
  171. rd = 250
  172. x = 150
  173. y = 900
  174.  
  175. 'set initial sun color values
  176. sr = 220
  177. sg = 220
  178.  
  179. '''make a sun'''
  180. 'drawing bounds are hard-coded from cell(1,650) to (300,800)
  181. For i = 1 To 300
  182.     For j = 650 To 800
  183.         If ((i - x) ^ 2) + ((j - y) ^ 2) <= rd ^ 2 Then
  184.        
  185.             'same kind of deal for planets, except this is limited to 1 in 4
  186.            '(only changing R/G values)
  187.            rndRGB = (Math.Rnd * 4 + 0.5) \ 1
  188.            
  189.             If rndRGB = 1 Then
  190.                 sr = sr + 5
  191.             End If
  192.            
  193.             If rndRGB = 2 Then
  194.                 sr = sr - 5
  195.             End If
  196.            
  197.             If rndRGB = 3 Then
  198.                 sg = sg + 5
  199.             End If
  200.            
  201.             If rndRGB = 4 Then
  202.                 sg = sg - 5
  203.             End If
  204.            
  205.            
  206.             If sr > smax Then
  207.                 sr = smax
  208.             End If
  209.            
  210.             If sr < smin Then
  211.                 sr = smin
  212.             End If
  213.            
  214.             sg = sr
  215.  
  216.            
  217.             Cells(i, j).Interior.Color = RGB(sr, sg, 0)
  218.         End If
  219.     Next j
  220. Next i
  221.  
  222. '''Enjoy'''
  223.  
  224. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement