Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Sub drawMandelbrotBW()
- Sheet1.Activate
- ActiveSheet.Cells(1, 1).Select
- Dim width As Integer
- Dim height As Integer
- Dim max As Integer
- Dim Row As Integer
- Dim Col As Integer
- Dim black As Long
- width = 1920
- height = 1080
- max = 30
- black = RGB(0, 0, 0)
- Dim c_re As Double
- Dim c_im As Double
- Dim x As Double
- Dim y As Double
- Dim iterations As Integer
- Dim x_new As Double
- Dim color_val As Double
- For Row = 1 To height
- For Col = 1 To width
- c_re = (Col - width / 2) * 4 / width
- c_im = (Row - height / 2) * 4 / width
- x = 0
- y = 0
- iterations = 0
- Do While (x ^ 2 + y ^ 2) < 4 And iterations < max
- x_new = x ^ 2 - y ^ 2 + c_re
- y = 2 * x * y + c_im
- x = x_new
- iterations = iterations + 1
- Loop
- If iterations < max Then
- color_val = 255 - (iterations * 8.5)
- Cells(Row, Col).Interior.Color = RGB(color_val, color_val, color_val)
- Else
- Cells(Row, Col).Interior.Color = RGB(0, 0, 0)
- End If
- Next Col
- Next Row
- End Sub
- Public Sub drawMandelbrotColor()
- Sheet1.Activate
- ActiveSheet.Cells(1, 1).Select
- Dim width As Integer
- Dim height As Integer
- Dim max As Integer
- Dim Row As Integer
- Dim Col As Integer
- Dim black As Long
- width = 1920
- height = 1080
- max = 40
- black = RGB(0, 0, 0)
- Dim c_re As Double
- Dim c_im As Double
- Dim x As Double
- Dim y As Double
- Dim iterations As Integer
- Dim x_new As Double
- Dim color_val As Double
- Dim pallete(40) As Long
- Call initializePallete(pallete, max)
- For Row = 1 To height
- For Col = 1 To width
- c_re = (Col - width / 2) * 4 / width
- c_im = (Row - height / 2) * 4 / width
- x = 0
- y = 0
- iterations = 0
- Do While (x ^ 2 + y ^ 2) < 4 And iterations < max
- x_new = x ^ 2 - y ^ 2 + c_re
- y = 2 * x * y + c_im
- x = x_new
- iterations = iterations + 1
- Loop
- If iterations < max Then
- Cells(Row, Col).Interior.Color = pallete(iterations)
- Else
- Cells(Row, Col).Interior.Color = RGB(0, 0, 0)
- End If
- Next Col
- Next Row
- End Sub
- Public Sub initializePallete(pallete() As Long, max As Integer)
- colorchunks = max / 4
- c1R = 0
- c1G = 7
- c1B = 100
- c2R = 32
- c2G = 107
- c2B = 203
- c3R = 237
- c3G = 255
- c3B = 255
- c4R = 255
- c4G = 170
- c4B = 0
- c5R = 0
- c5G = 2
- c5B = 0
- r = (c2R - c1R) / colorchunks
- g = (c2G - c1G) / colorchunks
- b = (c2B - c1B) / colorchunks
- For i = 0 To colorchunks
- pallete(i) = RGB(c1R, c1G, c1B)
- c1R = c1R + r
- c1G = c1G + g
- c1B = c1B + b
- Next
- r = (c3R - c2R) / colorchunks
- g = (c3G - c2G) / colorchunks
- b = (c3B - c2B) / colorchunks
- For i = colorchunks To colorchunks * 2
- pallete(i) = RGB(c2R, c2G, c2B)
- c2R = c2R + r
- c2G = c2G + g
- c2B = c2B + b
- Next
- r = (c4R - c3R) / colorchunks
- g = (c4G - c3G) / colorchunks
- b = (c4B - c3B) / colorchunks
- MsgBox (CStr(r) + " " + CStr(g) + " " + CStr(b))
- For i = (colorchunks * 2) To (colorchunks * 3)
- pallete(i) = RGB(c3R, c3G, c3B)
- c3R = c3R + r
- c3G = c3G + g
- c3B = c3B + b
- Next
- r = (c5R - c4R) / colorchunks
- g = (c5G - c4G) / colorchunks
- b = (c5B - c4B) / colorchunks
- For i = colorchunks * 3 To colorchunks * 4
- pallete(i) = RGB(c4R, c4G, c4B)
- c4R = c4R + r
- c4G = c4G + g
- c4B = c4B + b
- Next
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement