Logo by Pauldelbrot - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. November 29, 2025, 09:14:22 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Hello from Tampa, Florida  (Read 1663 times)
Description: Advice Welcome
0 Members and 1 Guest are viewing this topic.
nimzo
Guest
« on: November 17, 2008, 03:44:56 AM »

Hello all,

I recently became interested in fractals, but have limited computer and math skills. After researching mandelbrot and julia on the internet, I managed to create a visual basic program that successfully draws mandelbrot, although my coloring algorithm is rudimentary.  My program for julia has not worked very well for any of the parameters that I have used, but I am just guessing what will work and really don't know what I'm doing.  I would appreciate some input on the following.

-Any suggestions for further reading books or internet sites) given that my math and computer skills are limited (I had a year of college calculus about 30 years ago). 
-Can I get along with visual basic, or do I need to learn C. I 'm sure there must be better ways to color the points, but I haven't figured it out.
- Any comments on why my julia program doesn't work would also be appreciated.  Am I close? Please see below.

Thanks!

Public Class Form1

    Dim z_real As Double   'real value of z
    Dim z_imag As Double  'imaginary of z
    Dim c_imag As Double
    Dim c_real As Double
    Dim iteration As Integer 'the interation counter
    Dim length_z As Double  'length of z,  sqrt(length_z)>2 => z->infinity
    Dim old_zreal As Double
    Dim old_zimag As Double
    Dim max_iteration As Integer = 200

    Public Function Calc_Pixel(ByVal z_real, ByVal z_imag)
        Dim n As Integer = 1
        iteration = 0
        old_zreal = 0
        c_real = -0.14
        c_imag = 0.67

        Do
            z_real = z_real * z_real - z_imag * z_imag + c_real
            z_imag = 2 * old_zreal * z_imag + c_imag
            iteration = iteration + 1
            length_z = z_real * z_real + z_imag * z_imag
            old_zreal = z_real
            n = n + 1
            If length_z > 4 Or n > max_iteration Then
            End If
        Loop Until n = max_iteration Or length_z > 4
        Return iteration
    End Function


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim blackPen As New Drawing.Pen(Color.Black, 1)
        Dim redPen As New Drawing.Pen(Color.Red, 1)
        Dim orangePen As New Drawing.Pen(Color.Orange, 1)
        Dim yellowPen As New Drawing.Pen(Color.Yellow, 1)
        Dim greenPen As New Drawing.Pen(Color.Green, 1)
        Dim bluePen As New Drawing.Pen(Color.Blue, 1)
        Dim purplePen As New Drawing.Pen(Color.Purple, 1)

       ' some of the values that I tried are commented out
        Dim MinX As Double = -0.15117152      '-1.5 '-2.25 '- 1.254024 '-0.75104 ' -0.95
        Dim MaxX As Double = 2.15112072      '1.5 '0.75 '-1.252861 '-0.7401 '-0.88333 '
        Dim MinY As Double = -0.58244478      '-1.81818182 '-1.5 '0.046252 '0.10511 '0.23333 '
        Dim MaxY As Double = 2.5823832         '1.81818182 '1.5 '0.047415 '0.11536 '0.3 '
        Dim dx, dy As Double
        Dim x, y As Integer

        Dim screen_res_width As Integer = 640 '960
        Dim screen_res_height As Integer = 480 '720


        dx = (MaxX - MinX) / screen_res_width  '0.0046875
        dy = (MaxY - MinY) / screen_res_height  '0.00625



        For y = 0 To screen_res_height - 1
            For x = 0 To screen_res_width - 1
                z_real = MinX + x * dx
                z_imag = MinY + y * dy
                Calc_Pixel(z_real, z_imag)
                If iteration = max_iteration - 1 Then e.Graphics.DrawRectangle(blackPen, x, y, 1, 1)
                If iteration >= 190 And iteration < max_iteration - 1 Then e.Graphics.DrawRectangle(purplePen, x, y, 1, 1)
                If iteration >= 20 And iteration < 190 Then e.Graphics.DrawRectangle(bluePen, x, y, 1, 1)
                If iteration >= 8 And iteration < 20 Then e.Graphics.DrawRectangle(greenPen, x, y, 1, 1)
                If iteration >= 6 And iteration < 8 Then e.Graphics.DrawRectangle(yellowPen, x, y, 1, 1)
                If iteration >= 4 And iteration < 6 Then e.Graphics.DrawRectangle(orangePen, x, y, 1, 1)
                If iteration >= 0 And iteration < 4 Then e.Graphics.DrawRectangle(redPen, x, y, 1, 1)

            Next x
        Next y


    End Sub
End Class

Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #1 on: November 17, 2008, 12:15:49 PM »

hi and welcome to the forum,

please check out the following section of the board

http://www.fractalforums.com/introduction-to-fractals/

there is at least one great introduction to the calculus of mandelbrot fractals!
Logged

---

divide and conquer - iterate and rule - chaos is No random!
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #2 on: November 17, 2008, 12:22:24 PM »

now for your little program ...


first of all you need a better structure, perhaps you have heard that global variables are evil,

you are saving your iteration value in a global variable, one improvement would be to make the iteration value a return value of the Calc_Pixel function



second thing is the way you color the set, you make large ranges of predefined colors, this is a bit weird, my suggestion would be
to define a Iteration->Color function

(i do not have visual basic skills, but perhaps you understand what i want to say )

Public Function Iteration_To_Color(int iter)

// Calculate a color value, and create a pen object for it, either here or somewhere else...

End Function


third: create sub functions for the calculus:


Public Function ComplexLength(real,imag)

// The sqrt value could be ommited, but you should rename the function if you do so ....
return sqrt(real * real + imag * imag);

End Function


you see, it might be useful if you invent a complex number class, consisting of a real, and an imaginary part,
the complex number class would define the length function, and the mandelbrot formula function would get this
class as input ... smiley


got it ?

cheers
ck



fourth: create sub function for the formula you want to visualise
   

Public Function ComplexLength(real,imag)
/*
  z_real = z_real * z_real - z_imag * z_imag + c_real
            z_imag = 2 * old_zreal * z_imag + c_imag
*/
return  a complex value here
« Last Edit: November 17, 2008, 12:26:34 PM by Trifox » Logged

---

divide and conquer - iterate and rule - chaos is No random!
nimzo
Guest
« Reply #3 on: November 18, 2008, 03:41:44 AM »

Thanks very much for your thoughts.  My inexperience as a programmer apparently shows.  I'm not sure that I follow all that you said, so I have some follow up comments/questions below.  By the way, the program does not draw anything that looks like any Julia that I have ever seen so there is apparently a problem with the program logic.  As I mentioned, my Mandelbrot program works just fine, and I am using essentially the same program except that I am iterating real and imaginary z and choosing and arbitrary real and imaginary c.  Thanks again.



[/color]
now for your little program ...


first of all you need a better structure, perhaps you have heard that global variables are evil,

you are saving your iteration value in a global variable, one improvement would be to make the iteration value a return value of the Calc_Pixel function  I THOUGH THAT WAS DOING THIS.  THE FUNCTION CALC_PIXEL RETURNS THE VALUE "ITERATION" --NO?



second thing is the way you color the set, you make large ranges of predefined colors, this is a bit weird, my suggestion would be
to define a Iteration->Color function *** MY METHODOLOGY FOR COLORING THE PIXELS WAS STRICTLY TRIAL AND ERROR.  I HAD NO IDEA WHAT I WAS DOING  -- JUST TRYING TO SEE IF ANYTHING WORKS.  NOT SURE WHAT TO DO HERE.  DO YOU KNOW OF ANY RESOURCES WHERE I CAN GET SOME INFO AS TO WHAT WORKS WELL

(i do not have visual basic skills, but perhaps you understand what i want to say )

Public Function Iteration_To_Color(int iter)

// Calculate a color value, and create a pen object for it, either here or somewhere else... 

End Function


third: create sub functions for the calculus:


Public Function ComplexLength(real,imag)

// The sqrt value could be ommited, but you should rename the function if you do so ....
return sqrt(real * real + imag * imag);

End Function


you see, it might be useful if you invent a complex number class, consisting of a real, and an imaginary part,
the complex number class would define the length function, and the mandelbrot formula function would get this
class as input ... smiley  I ASSUME THAT THIS AND THE FOLLOWING COMMENTS ADDRESS MY FORM/STRUCTURE AND WOULD NOT AFFECT THE PROGRAM FUNCTION? YES?


got it ?

cheers
ck



fourth: create sub function for the formula you want to visualise
  

Public Function ComplexLength(real,imag)
/*
  z_real = z_real * z_real - z_imag * z_imag + c_real
            z_imag = 2 * old_zreal * z_imag + c_imag
*/
return  a complex value here
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #4 on: November 18, 2008, 11:45:14 AM »

ok, sorry, i missed that the function calpixel returned the value, this is fine police police police

ok, now let me explain the difference of julia/mandelbrot, THE ONLY thing youj need to change is the starting value,
e.g. if you have a programm ready whnich calculates the mandelbrot, you have somwhere 2 values:

a starting value ( for mandelbrot this is often (0,0) )
and a seed value ( for mandelbrot this is often ( pixelreal,pixelimag))


If you want to do a julia, pleas go like the following:

just exchange the above values

a starting value ( ( pixelreal,pixelimag) )
and a seed value ( for mandelbrot it was(0,0) )


you should now see a big circle on your screen and if you change the seed from (0,0) to e.g. (0.5,0) you will see a julia
 afro afro
Logged

---

divide and conquer - iterate and rule - chaos is No random!
nimzo
Guest
« Reply #5 on: November 19, 2008, 02:52:07 AM »

Sorry to trouble you again but if you could try one more time I would be most appreciative.  I thought I was doing just what you suggested.  Below is my iteration function.  In my Mandelbrot program, CA and CBi are the inputs for this function, with the starting values being the coordinates of the upper left corner of my screen.  A and Bi start out as 0.  In my julia program below, A and Bi are the inputs for the function, again with the starting values being the coordinates of the upper left had corner of my screen.  CA and CBi are fixed.  Isn't this what you are saying? Whether I use 0,0 or .5,0 for CA and CBi, I get what looks like a big partial X on the screen.  Thanks again.


Public Function Calc_Pixel(ByVal A, ByVal Bi)
        Dim n As Integer = 1
        CA = 0
        CBi = 0.5
        iteration = 0
        old_A = 0

        Do
            A = A * A - Bi * Bi + CA
            Bi = 2 * old_A * Bi + CBi
            iteration = iteration + 1
            length_z = A * A + Bi * Bi
            old_A = A
            n = n + 1
            If length_z > 4 Or n > max_iteration Then
            End If
        Loop Until n = max_iteration Or length_z > 4
        Return iteration

    End Function
Logged
nimzo
Guest
« Reply #6 on: November 19, 2008, 04:40:44 AM »

A follow up note -- the lines

If length_z > 4 Or n > max_iteration Then
            End If

should not be there but they do not affect the execution of the program.
Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Hi from Florida Meet & Greet ginatheloca 2 781 Last post February 11, 2011, 12:24:15 AM
by Sockratease
Hello from Florida Meet & Greet eiffie 2 608 Last post April 01, 2011, 09:26:04 PM
by Erisian
Hello from Florida Meet & Greet sray 1 581 Last post October 11, 2013, 12:23:44 AM
by Nahee_Enterprises

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.473 seconds with 27 queries. (Pretty URLs adds 0.039s, 2q)