Results 1 to 18 of 18

Thread: Fractals!

  1. #1

    Thread Starter
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245

    Fractals!

    I'm just curious, has anyone else written a program to map fractals in VB or VB.NET? I've written one, and really enjoyed it. I'm now in the process of revising it.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  2. #2
    Hyperactive Member DavidHooper's Avatar
    Join Date
    Apr 2001
    Posts
    357
    Can't say I have Sheppe. Just out of interest, what were the interesting parts? Is it mostly mathematical coding or more graphical?
    There are 10 types of people in the world - those that understand binary, and those that don't.

  3. #3

    Thread Starter
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Originally posted by DavidHooper
    Can't say I have Sheppe. Just out of interest, what were the interesting parts? Is it mostly mathematical coding or more graphical?
    Well, in short, you map a fractal by calculating coordinates on an imaginary screen, and the coordinates are calculated using any number of different formulas. Anyhow, each pixel on the actual screen has a set of these imaginary coordinates, and you determine the pixel's color by seeing how many iterations it takes the said formula to cause the coordinates on the imaginary screen to go beyond its bounds.

    I'm kinda confusing even myself now, but I'll close by saying that the thing that makes fractals cool is that they are infinite, and you can zoom in/out on a particular coordinate as much as you like, and each new coordinate will give you a new picture.

    I've attached a fractal that I calculated with my proggy. This was calculated using the Mandelbrot set. I've shrunk the original image, so the quality and detail isn't there, but it gives you a general idea.
    Attached Images Attached Images  
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  4. #4
    Hyperactive Member DavidHooper's Avatar
    Join Date
    Apr 2001
    Posts
    357
    Oh right, I always wondered what determined the colour of each point.

    Just out of interest, what are the limits that the computer can handle? I imagine you can only zoom in so far with VB precision?
    There are 10 types of people in the world - those that understand binary, and those that don't.

  5. #5

    Thread Starter
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Originally posted by DavidHooper
    Oh right, I always wondered what determined the colour of each point.

    Just out of interest, what are the limits that the computer can handle? I imagine you can only zoom in so far with VB precision?
    I'm not sure on the limits - using VB's double data type, I imagine you could go pretty far. I haven't hit the limits, and I've zoomed in a good ways. I run out of patience before I hit the limits ; it can take hours or days to calculate a fractal, depending on how precise you want to be, and the size of the fractal image.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Anyone have any coded fractals in VB?

    We could share algos with eachother and perhaps build a program to run given algos.

    It could be fun.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    as you approach the precision limits of the floating point the fractal gets all pixelerated I made a prog rendering mandelbrot long ago, the colour for a certain point of a the screen depends on your own function of the amount of iterations before the equation tends to infinity(in the algoritm you test if the modulus exceeds a certain value), in mandelbrots case
    zn=zn-12+C where C is the complex value mapped to your screen of the point you want to decide the colour for.
    the first iteration would be
    C
    the second
    C(C+1)
    the third
    C(C+C2)2
    etc..
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Banned DiGiTalErRoR's Avatar
    Join Date
    Sep 2002
    Posts
    68
    I've made a simple program to map a fractal I made up.

  9. #9
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Anybody interested in writing some fractal program that'll be really spiffy?

  10. #10
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    A very interesting fractal is based on the Newton method for cube root using complex arithmetic.

    There are three cube roots located 120 degrees apart on the unit circle around the origin in the complex plane.

    The basic idea is simple. Pick a point as the first approximation to the cube root and use Newton method to converge on a root. Color the starting point depending on which root you converge to. Red, blue, and yellow are good choices for the three colors.

    This fractal has an amazing property. All the border points are triple boundary points. To understand a triple boundary point, visualize a circle divided into three equal regions by 3 radii. The points on each radius (except for the center point) are ordinary boundary points between two of the three regions. The center of the circle is a triple boundary point.

    Only graphics with infinitesimal fractal boundaries can have this property.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  11. #11
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    What are the equations, and their properties?

  12. #12
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    Find cube roots of one via Newton successive approximations.

    NextZ = 2z/3 + 1/3z2, where z is complex.

    For z = x + iy, the three cube reoots of one are the following.

    (1, 0)
    (-.5, SquareRoot(.75) )
    (-.5, -SquareRoot(.75) )

    Pick starting points at random. Use above formula until you reach a root (or close to one). Color the starting point with the color assigned to that root. Red Blue, & Yellow seem like a good set of colors.

    You could use some systematic method of picking starting points instead of using random points.

    For this fractal, it seems reasonable to use Pixel ScaleMode in the Picture Box where the image is generated.

    I think the Cube root fractal is most interesting, but you could also use Newton for 4th, 5th, et cetera roots to generate other fractals. You could use it to generate fractals based on roots of a cubic polynomial, which generates a non-symmetric fractal.

    Iteration formulae for 4th & 5th roots are as follows.

    NextZ = 3z/4 + 1/4z3
    NextZ = 4z/5 + 1/5z4

    I expect you to see the pattern if you want to play with higher roots.

    This post written in a hurry. Verify before taking the above advice. Sorry if there are typo's.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  13. #13
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Guv,

    Is this what you mean, or am I totally wrong?
    I'm not sure how to implement "nearing" a root. At the moment I check whether the distance to one of the roots is less than 1.
    At least the image looks interesting and very fractal-like
    Attached Images Attached Images  

  14. #14

    Thread Starter
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Originally posted by DiGiTaIErRoR
    Anyone have any coded fractals in VB?

    We could share algos with eachother and perhaps build a program to run given algos.

    It could be fun.
    Already done. I started this thread because I wrote the said program. I wrote it in VB.NET, and it currently displays the Julia Set, the Mandelbrot Set, the Sierpinski triangle, and some fractals of my own design.
    Last edited by Sheppe; Oct 24th, 2002 at 04:40 PM.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  15. #15

    Thread Starter
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Originally posted by riis
    Guv,

    Is this what you mean, or am I totally wrong?
    I'm not sure how to implement "nearing" a root. At the moment I check whether the distance to one of the roots is less than 1.
    At least the image looks interesting and very fractal-like
    Nicely done.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  16. #16
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    Sheppe: In general when I test for convergence to a complex value, I divide the previous value by the current value and compare the quotient to (1, 0), by comparing real part to one and complex part to zero. Since Newton and most other methods converge exponentially, a value like (1.000 000 1, .000 000 1) for the quotient indicates convergence to at least ten decimal places, probably more.

    For converging to the known roots of 1, you can obviously compare the latest value to (-.5, .866 025 ), (-.5, -.866 025), and (1, 0). When finding roots instead of doing fractals, I usually do a comparison using 6 digits to the right of the decimal point and then do one more iteration without testing. This is probably overkill, but with the speed of a typical PC, it does not cost a noticable amount of CPU time.

    For the cube root iteration, I would expect that a 3-digit comparison would be good enough to identify the root you are converging to. Note that one more iteration is likely to get 6-digit precision and you can be certain that you have the correct root.

    I am almost certain that you need to test both real and complex parts. You could get a value like (-.9, .866025) and discover that it does not converge to (-.5, .866 025).

    BTW: Most people I discuss fractals with do not appreciate the weird property of the cube root fractal, which has only triple boundary points between the various regions.

    With Ink Jet & laser printers capable of 300 to 600 dots per inch, a printed fractal is far more precise than what can be shown on an ordinary monitor. Note that 1200*1600 on a 17 inch monitor is about 1200/13 = 92 pixels per inch.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  17. #17
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    Riis: I ignored your post the first time I read it. It did not make sense. Then I noticed that you had a .gif file attached.

    That .gif file does not seem right to me. The cube root fractal has group three (120 degree) symmetry, and your .giff seems to have group 4 (90 degree) symmetry.

    Id est: If you rotate the cube root fractal by 120 degrees, it looks the same. Your fractal looks the same (or similar) if you rotate 90 degrees.

    Did you notice my previous post, which mentions that a good Ink Jet or laser printer does a better job of showing most fractals than is done by a monitor display?

    The cube root fractal is so well known that I am sure you can find a good version of it in a library or on the internet somewhere.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  18. #18
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Hello Guv,

    Sorry that I forgot to mention I had an image attached.
    I've just quickly "hacked" something in VB, but since I'm absolutely not a fractal expert, I had no idea I was doing a good job. Because of the little time I spent to it, I didn't search the internet for correct formulas either. Maybe I'll try when I have more time.

    "My" fractal doesn't have 90 degree symmetry, only 180 degree symmetry. You can mirror it however, but then the green and blue colors will be swapped.

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