Results 1 to 2 of 2

Thread: Mandelbrot Fractal Drawer

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    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

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Mandelbrot Fractal Drawer

    Quote Originally Posted by NinjaNic View Post
    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?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

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
  •  



Click Here to Expand Forum to Full Width