Logo by Fiery - 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: Visit the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. April 19, 2024, 05:50:58 AM


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: Smooth colouring of convergent fractals  (Read 7552 times)
0 Members and 1 Guest are viewing this topic.
zenzero-2001
Explorer
****
Posts: 42


« on: June 24, 2011, 08:01:27 PM »

Hi All

I am trying to implement David Makin's formula (as described here: http://www.fractalforums.com/programming/help!-newton-fractal-smooth-shading/ and in his Ultra Fractal formula file) for smooth colouring of convergent fractals, but I am experiencing some difficulties. Hopefully he is reading this! smiley

I have not yet tried applying it to the Magnet fractals (which are both convergent and divergent), but am currently trying to smoothly colour the Manget and Nova fractals with the auto-power variant of the formula. I can not get it to work at all with the Nova fractal, but with the Newton fractal it works properly with positive low powers (eg 3), but at higher powers the result becomes progressively less smooth. With negative powers, the inside is smooth but the outside is not. I know the formula should work because it does so under all these conditions with Ultra Fractal. Anyway here is some of my code, maybe somebody can see a silly mistake? smiley

Code:
vector<Element>* Newton::calculateNoOrbit(vector<Point>* points)
{
    vector<Point>::const_iterator i = points->begin();

    int iterations;
    double zx;
    double zy;
    double z2x;
    double z2y;
    double z3x;
    double z3y;
    double zx_old = DBL_MAX;
    double zy_old = DBL_MAX;
    double zx_older = DBL_MAX;
    double zy_older = DBL_MAX;
    double zx_delta;
    double zy_delta;
    double denominator;

    double radius;
    double modulus;
    double phi;

    const double exponent2 = exponent - 1.0;
    const double temp1 = 0.5 * exponent;
    const double temp2 = 0.5 * exponent2;

    getCoord(i->x, i->y, zx, zy);

    for(iterations = 0; iterations < maxIterations; ++iterations)
    {
        // Calculate |z - z_old| for bailout check
        zx_delta = zx - zx_old;
        zy_delta = zy - zy_old;

        zx_delta *= zx_delta;
        zy_delta *= zy_delta;

        // Check |z - z_old| against bailout
        if(zx_delta + zy_delta < bailout)
        { break; }

        // Update z_older and z_old
        zx_older = zx_old;
        zy_older = zy_old;
        zx_old = zx;
        zy_old = zy;

        // Calculate z^exponent - 1
        radius = zx * zx + zy * zy;
        modulus = exp(log(radius) * temp1);
        phi = exponent * atan2(zy, zx);

        z3x = modulus * cos(phi) - 1.0;
        z3y = modulus * sin(phi);

        // Calculate exponent * z^(exponent - 1)
        modulus = exp(log(radius) * temp2);
        phi = exponent2 * atan2(zy_old, zx_old);

        z2x = modulus * cos(phi) * exponent;
        z2y = modulus * sin(phi) * exponent;

        // Calculate the division and subtract from z
        denominator = z2x * z2x + z2y * z2y;

        if(denominator == 0.0)
        { break; }

        zx -= (z3x * z2x + z3y * z2y) / denominator;
        zy -= (z3y * z2x - z3x * z2y) / denominator;
    }

    results.clear();

    // Calculate smooth color
    zx_delta = zx - zx_old;
    zy_delta = zy - zy_old;
    double m1 = log(sqrt(zx_delta * zx_delta + zy_delta * zy_delta));

    zx_delta = zx_old - zx_older;
    zy_delta = zy_old - zy_older;
    double m2 = log(sqrt(zx_delta * zx_delta + zy_delta * zy_delta));

    double fractional = iterations + (log(-0.5 * log(bailout)) - log(-0.5 * m1)) / log( m1 / m2 );
    writeResult(i->x, i->y, iterations, fractional);

    return &results;
}

Thanks!
Logged
fractalrebel
Fractal Lover
**
Posts: 211



WWW
« Reply #1 on: June 24, 2011, 10:31:05 PM »

My favorite, which is nowhere as complicated as the algorithm above, is called general smoothing:

initialize with

iterexp = 0
zold = z

loop until bailout:
  iterexp =iterexp + exp(-cabs(z)-0.5/(cabs(zold - z)))
  zold = z

Then use iterexp to color the fractal. It works with both convergent and divergent fractals, so it iwll work for all regions of a magnet fractal
« Last Edit: June 24, 2011, 10:35:47 PM by fractalrebel » Logged

fractalrebel
Fractal Lover
**
Posts: 211



WWW
« Reply #2 on: June 24, 2011, 10:38:27 PM »

cabs is an UltraFractal function which you may not know. For a complex number c = a + ib

cabs(c) = sqrt(a^2 + b^2)
Logged

fractalrebel
Fractal Lover
**
Posts: 211



WWW
« Reply #3 on: June 24, 2011, 10:42:07 PM »

For those of you who have Ultrafractal the General Smoothing coloring algorithm is in reb.ulb and the implementation in reb5.ucl.
Logged

zenzero-2001
Explorer
****
Posts: 42


« Reply #4 on: June 24, 2011, 11:45:34 PM »

Thanks fractalrebel, that is a very nice algorithm. I had look at it in Ultra Fractal.

I would still like to get the other smoothing algorithm working however, because it more closely matches the contours of the level sets method.
Logged
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #5 on: June 25, 2011, 12:56:27 AM »

Ron actually sort-of gave the answer - in your implementation you are using the full magnitude calculation i.e. actually getting the square roots.

In both Ultra Fractal and Fractint (and some other fractal software) then:

|x+i*y| = x^2+y^2
abs(x+i*y) = abs(x)+i*abs(y)

and as Ron said:

cabs(x+i*y) = sqrt(x^2+y^2)

Whereas in formal math |x+i*y|=abs(x+i*y)=cabs(x+i*y)=sqrt(x^2+y^2)

To check on the above and indeed how most complex stuff is generally implemented in Fractint and Ultra Fractal see the "Trig identities" section here:

http://www.nahee.com/spanky/www/fractint/append_a_misc.html

So in your code just get rid of the square roots - including for the bailout test i.e. such that the bailout tests (zx-zoldx)^2+(zy-zoldy)^2 instead of the square root of this.
The reason for avoiding the square roots is that they are a major slow-down when used wink

edit: Also taking away the square roots should give you the reason for the "-0.5*log" in my calculations as here we do actually need the log of the square root and of course -0.5*log(x^2) = -log(sqrt(x^2)). (The minus signs being because we're testing convergent in this case)
« Last Edit: June 25, 2011, 01:06:50 AM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
zenzero-2001
Explorer
****
Posts: 42


« Reply #6 on: June 25, 2011, 02:00:30 AM »

Thanks David! I wondered what the 0.5 was for smiley I will have a play with the code tomorrow as I'm in bed now and it is time for sleep.

I noticed that your formula does not seem to work so well for the magnet fractals in Ultra Fractal, especially when adjusting the colour density. Is there a way to mitigate this, perhaps by using the fudge factor?

I am developing an open source cross platform fractal explorer written in Qt, the smooth colour algorithm will be used in it. I hope to release the first version later this year.
Logged
fractalrebel
Fractal Lover
**
Posts: 211



WWW
« Reply #7 on: June 25, 2011, 02:13:58 AM »

Here is another one which keeps the level sets. This also works well with the magnet formula. Set the divergent bailout on the fractal formula to 1e20 and the convergent bailout to 1e-20. The coloring bailout can be set to either 1e20 or 1e-20 - both work.

Harkonen Vespstas smoothing

loop until bailout:
    zold2 = zold
    zold = z

After bailout
    power = log(|z - zold|) / log(|zold - zold2|)
    f = (log(log(@bailout)) - log(log(1/(|(zold - z)|))))/log(power)

    color = 0.05*(iterations+f)

The |complex num| usage is the UltraFractal and Fractint usage, not the standard mathematical usage.
« Last Edit: June 25, 2011, 02:40:10 AM by fractalrebel » Logged

David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #8 on: June 25, 2011, 02:43:54 AM »

Thanks David! I wondered what the 0.5 was for smiley I will have a play with the code tomorrow as I'm in bed now and it is time for sleep.

I noticed that your formula does not seem to work so well for the magnet fractals in Ultra Fractal, especially when adjusting the colour density. Is there a way to mitigate this, perhaps by using the fudge factor?

I am developing an open source cross platform fractal explorer written in Qt, the smooth colour algorithm will be used in it. I hope to release the first version later this year.


Depends which formula/s of mine you are starting from - my best attempts for the Magnet formulas are UF5-class formulas in mmf.ulb, see this thread here at ff:

http://www.fractalforums.com/mathematics/convergent-distance-estimation-t1566/

However all my convergent DE colourings exhibit the same "problem" i.e. singularities (at the roots in the Newtons and equivalent locations in the Magnets and other convergent formulas/areas).
I did manage a work around to fix the issue in Newtons for the solutions of plain z^n-v at least where n is an integer, but extending that further was beyond my formal math knowledge !
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #9 on: June 25, 2011, 03:26:58 AM »

I should add that for point attractors (and indeed periodic attractors) then it's always a lot more accurate to test against known value/s for the attractor for a given orbit (pixel) rather than testing against previous values - for instance for a point attractor use:

z-attractor and zold-attractor instead of z-zold and z-zolder

For a standard Magnet formula that would be (1,0).
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #10 on: June 25, 2011, 03:51:03 AM »

Aargh - sorry, just remembered you were talking about level sets - the important thing is that the bailout values must match those used in the main formula even when using the "auto-power" method, AFAIK my UF5 class colouring "Extended Cilia" in mmf.ulb should work for any Magnet formula provided the bailout values are set correctly - note that to use it you should choose the colouring formula from "Standard.ucl" that allows plug-ins and plug-in "MMF Extended Cilia" from mmf.ulb.
Edit: And initially set the Cilia colouring parameter to "Just Iteration" for both divergent and convergent areas smiley
« Last Edit: June 25, 2011, 03:56:00 AM by David Makin » Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
zenzero-2001
Explorer
****
Posts: 42


« Reply #11 on: June 25, 2011, 06:14:47 PM »

The Cilia colouring is interesting but a bit complicated!

I have your formula working now for both Magnet fractals, Nova and Newton. It actually works better with my code on the Magnet fractals than it does in Ultra Fractal for some reason. I still have banding on the outside of the Newton fractal for negative powers, but this is because of trying to find the log of zero. smiley

I see that Ron's method is similar to exponential smoothing, so there would be some overhead finding the exponent every iteration. The results are very nice though.

I don't have too many things left to do before releasing the first version of my program, the biggest being the gradient editor and a few bug fixes. Here are some of the features:

MDI Interface
Animated pan and zoom (similar to Fractal eXtreme)
Arbitrary Precision (using MPIR and MPFR)
Smooth colouring smiley
Fullscreen mode
Colour cycling
Julia animation
Currently supported fractals: Mandelbrot, Mandelbrot3, Mandelbrot4, Mandelbrot5, Mandelbrot6, Mandelbrot Inverse, Mandelbrot General Power, Burning Ship, Lambda, Phoenix, Newton General Power, Nova, Magnet1, Magnet2

It utilises solid guessing, orbit detection and SSE2 intrinsics (for Mandelbrot) for speed. Hopefully, it will be a useful and enjoyable program to use.

I know just how much the World needs another fractal explorer. smiley

Thanks again for the help!

John
Logged
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #12 on: July 20, 2011, 12:54:20 AM »


Currently supported fractals: Mandelbrot, Mandelbrot3, Mandelbrot4, Mandelbrot5, Mandelbrot6, Mandelbrot Inverse, Mandelbrot General Power, Burning Ship, Lambda, Phoenix, Newton General Power, Nova, Magnet1, Magnet2

It utilises solid guessing, orbit detection and SSE2 intrinsics (for Mandelbrot) for speed. Hopefully, it will be a useful and enjoyable program to use.

I know just how much the World needs another fractal explorer. smiley

Thanks again for the help!

John

Of course if you really want patronage of your software to take off then it needs to have it's own parser/compiler - and now I guess both CPU and GPU support plus built-in support for 3D+ rendering (ray traced, voxel and 2D slices) with export to STL, VRML etc. as well as an animation engine for both 2D and 3D wink
And of course it should be available for Windows, OSX and Linux at a minimum but ideally also for iOS, Android and Blackberry.
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
zenzero-2001
Explorer
****
Posts: 42


« Reply #13 on: July 21, 2011, 01:10:47 AM »

Quote
Of course if you really want patronage of your software to take off then it needs to have it's own parser/compiler - and now I guess both CPU and GPU support plus built-in support for 3D+ rendering (ray traced, voxel and 2D slices) with export to STL, VRML etc. as well as an animation engine for both 2D and 3D wink
And of course it should be available for Windows, OSX and Linux at a minimum but ideally also for iOS, Android and Blackberry.

Yep, I should have all those done by tomorrow evening - no problem!  cheesy
Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Colouring Mandelbulb 3d paolo 4 2505 Last post July 13, 2011, 07:53:32 PM
by Madman
Convergent Evolution Movies Showcase (Rate My Movie) brasnacte 4 3108 Last post November 12, 2014, 09:25:25 PM
by brasnacte
Sinclair BASIC Mandelbrot smooth colouring Help & Support simon.snake 11 1058 Last post October 15, 2016, 05:11:20 PM
by simon.snake
Convergent-divergent fractals possibru? Kalles Fraktaler DarkBeam 0 1104 Last post February 12, 2017, 07:33:57 PM
by DarkBeam
Julia smooth-colouring : how to do ? Programming Matplotlib 14 16874 Last post May 16, 2017, 11:58:55 AM
by Matplotlib

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.187 seconds with 24 queries. (Pretty URLs adds 0.016s, 2q)