-
May 15th, 2016, 09:53 PM
#1
Thread Starter
Addicted Member
Mandelbrot Fractal Drawer
Hey all!
All thanks goes to this website. All I did was translate the code into VB with slight modifications. It draws the set at the specified location, zoom, and with the specified iterations (max). It's really interesting, plus, you can essentially zoom in an unlimited amount of times at any location.
Code:
Private Function Draw(max As Int32, W As Int32, H As Int32, Zoom As Single, X_Location As Single, Y_Location As Single) As Bitmap
Dim B As New Bitmap(W + 1, H + 1)
For row As Int32 = 0 To H Step 1
For col As Int32 = 0 To W Step 1
Dim c_re As Double = (col - W / 2.0) * (4 / Zoom) / W + X_Location
Dim c_im As Double = (row - H / 2.0) * (4 / Zoom) / W + Y_Location
Dim x As Double = 0
Dim y As Double = 0
Dim iteration As Int32 = 0
Do While (x * x + y * y <= 4 And iteration < max)
Dim x_new As Double = x * x - y * y + c_re
y = 2 * x * y + c_im
x = x_new
iteration += 1
Loop
Dim RGB As Int32 = CInt(254 * iteration / max)
If (iteration < max) Then B.SetPixel(col, row, Color.FromArgb(RGB, RGB, RGB)) Else B.SetPixel(col, row, Color.Black) ' B.SetPixel(col, row, Color.White) Else B.SetPixel(col, row, Color.Black)
Next col
Next row
Return B
End Function
Attachment 137995
Attachment 137997
~Nic
-
May 16th, 2016, 10:11 AM
#2
Re: Mandelbrot Fractal Drawer
Originally Posted by NinjaNic
Hey all!
All thanks goes to this website. All I did was translate the code into VB with slight modifications. It draws the set at the specified location, zoom, and with the specified iterations (max). It's really interesting, plus, you can essentially zoom in an unlimited amount of times at any location.
Code:
Private Function Draw(max As Int32, W As Int32, H As Int32, Zoom As Single, X_Location As Single, Y_Location As Single) As Bitmap
Dim B As New Bitmap(W + 1, H + 1)
For row As Int32 = 0 To H Step 1
For col As Int32 = 0 To W Step 1
Dim c_re As Double = (col - W / 2.0) * (4 / Zoom) / W + X_Location
Dim c_im As Double = (row - H / 2.0) * (4 / Zoom) / W + Y_Location
Dim x As Double = 0
Dim y As Double = 0
Dim iteration As Int32 = 0
Do While (x * x + y * y <= 4 And iteration < max)
Dim x_new As Double = x * x - y * y + c_re
y = 2 * x * y + c_im
x = x_new
iteration += 1
Loop
Dim RGB As Int32 = CInt(254 * iteration / max)
If (iteration < max) Then B.SetPixel(col, row, Color.FromArgb(RGB, RGB, RGB)) Else B.SetPixel(col, row, Color.Black) ' B.SetPixel(col, row, Color.White) Else B.SetPixel(col, row, Color.Black)
Next col
Next row
Return B
End Function
~Nic
Do you have a .Net project example in which this is used that you can post?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|