Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub playGod()
- Dim rd As Integer 'radius
- Dim rdMax As Integer 'max planetary radius
- Dim rdMin As Integer 'min planetary radius
- Dim x As Integer 'vertical location of planetary body's center
- Dim y As Integer 'horizontal location of planetary body's center
- Dim locMax As Integer 'max distance from 0,0 to spawn planet
- Dim locMin As Integer 'min distance from 0,0 to spawn planet
- Dim rndRGB As Integer 'random value used to determine which color to alter (r, g, or b)
- Dim r As Integer 'red color value
- Dim g As Integer 'green color value
- Dim b As Integer 'blue color value
- Dim sr As Integer 'red color value for the sun
- Dim sg As Integer 'green coor value for the sun
- Dim dimVal As Double 'value used to determine how much pixel should be dimmed (night-time side of a planet)
- Dim bodies As Integer 'number of planets to generate
- Dim max As Integer 'max RGB value
- Dim min As Integer 'min RGB value
- Dim smax As Integer 'sun max RGB value
- Dim smin As Integer 'sun min rgb value
- Cells.Clear 'remove everything
- 'make 4 planets
- bodies = 4
- 'each between radius 10 and 75
- rdMax = 75
- rdMin = 10
- 'centered somewhere between (0,0) and (300,300)
- locMax = 300
- locMin = 0
- 'RGB values can range from 0-255
- max = 255
- min = 0
- 'Red / Green values for the sun can range from 205-255
- smin = 205
- smax = 255
- ''start our RGB values at something random between 100 and 150 (floored to a multiple of 5)
- r = (((Math.Rnd * 50 + 0.5) \ 5) * 5) + 100
- g = (((Math.Rnd * 50 + 0.5) \ 5) * 5) + 100
- b = (((Math.Rnd * 50 + 0.5) \ 5) * 5) + 100
- ''generate space (i.e. make all cells black)
- Cells.Interior.Color = RGB(0, 0, 0)
- ''throw in some stars (i.e. set 1000 random cells to white)
- For i = 1 To 1000
- Cells((Math.Rnd * 300) \ 1, (Math.Rnd * 900) \ 1).Interior.Color = RGB(255, 255, 255)
- Next i
- ''make the planets
- For Z = 1 To bodies
- 'generate a random radius and location
- rd = ((Math.Rnd * (rdMax - rdMin)) \ 1) + rdMin
- x = ((Math.Rnd * (locMax - locMin)) \ 1) + locMin + rd
- y = ((Math.Rnd * (locMax - locMin)) \ 1) + locMin + rd
- 'do stuff within the center (x,y) +/- radiu
- 'I add 1 to the lower bound, and subtract 1 from the upper bound to remove what I like to call planetary nipples.
- For i = x - rd + 1 To x + rd - 1
- For j = y - rd + 1 To y + rd - 1
- 'determine how much we have to dim a cell, to make a shadow
- '"j" is the current horizontal location that we're drawing
- '"(y - rd + 1)" is our lower bound
- '"(y + rd - 1)" is out upperbound
- 'if the current cell is 50, lowerbound is 40, upper is 80:
- '(50-40)/(80-40) -> 10/40 -> 0.25
- dimVal = (j - (y - rd + 1)) / ((y + rd - 1) - (y - rd + 1))
- 'dimVal should never be 0, but this is here in case you wanted to add more shadow
- '(i.e. subtract something from the above dimVal equation)
- If dimVal <= 0 Then
- dimVal = 0
- End If
- 'check if our current current cell is within the defined circle
- 'using the Standard Form equation for the circle
- If ((i - x) ^ 2) + ((j - y) ^ 2) <= rd ^ 2 Then
- 'generate a random number between 1 and 6
- rndRGB = (Math.Rnd * 6 + 0.5) \ 1
- '1: increase red by 5
- '2: decrease red by 5
- '3: increase green by 5
- '4: decrease green by 5
- '5: increase blue by 5
- '6: decrease blue by 5
- If rndRGB = 1 Then
- r = r + 5
- End If
- If rndRGB = 2 Then
- r = r - 5
- End If
- If rndRGB = 3 Then
- g = g + 5
- End If
- If rndRGB = 4 Then
- g = g - 5
- End If
- If rndRGB = 5 Then
- b = b + 5
- End If
- If rndRGB = 6 Then
- b = b - 5
- End If
- 'make sure the values for RGB do
- 'not go outside the defined bounds
- If r > max Then
- r = max
- End If
- If r < min Then
- r = min
- End If
- If g > max Then
- g = max
- End If
- If g < min Then
- g = min
- End If
- If b > max Then
- b = max
- End If
- If b < min Then
- b = min
- End If
- 'set the current cells background color to RGB,
- 'multiplied by the amount we need to dim,
- 'floored to make sure the value stays an integer
- Cells(i, j).Interior.Color = RGB((r * dimVal) \ 1, (g * dimVal) \ 1, (b * dimVal) \ 1)
- End If
- Next j
- Next i
- Next Z
- '''set sun's properties'''
- 'radius 250, centered (150,900)
- '(keeping in mind x is our vertical value in this)
- rd = 250
- x = 150
- y = 900
- 'set initial sun color values
- sr = 220
- sg = 220
- '''make a sun'''
- 'drawing bounds are hard-coded from cell(1,650) to (300,800)
- For i = 1 To 300
- For j = 650 To 800
- If ((i - x) ^ 2) + ((j - y) ^ 2) <= rd ^ 2 Then
- 'same kind of deal for planets, except this is limited to 1 in 4
- '(only changing R/G values)
- rndRGB = (Math.Rnd * 4 + 0.5) \ 1
- If rndRGB = 1 Then
- sr = sr + 5
- End If
- If rndRGB = 2 Then
- sr = sr - 5
- End If
- If rndRGB = 3 Then
- sg = sg + 5
- End If
- If rndRGB = 4 Then
- sg = sg - 5
- End If
- If sr > smax Then
- sr = smax
- End If
- If sr < smin Then
- sr = smin
- End If
- sg = sr
- Cells(i, j).Interior.Color = RGB(sr, sg, 0)
- End If
- Next j
- Next i
- '''Enjoy'''
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement