• January 28, 2022, 12:26:14 PM

Author Topic:  Can anyone help me understand smooth coloring  (Read 250 times)

0 Members and 1 Guest are viewing this topic.

Offline Modinstaller

  • Fractal Freshman
  • *
  • Posts: 7
Can anyone help me understand smooth coloring
« on: January 13, 2022, 04:12:51 PM »
Hey all

I'm working on a small fractal program in C. I'm using a simple escape time algorithm. I came here a few weeks ago with a pixelation problem (which I still haven't fixed, shh).

My little fractal program is coming along nicely but it's still got color bands and now I come to you for help with smooth colors!

I've looked at this https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set#Continuous_(smooth)_coloring

I understand the part about calculating a floating point iteration number, and using it to get a new color with a ratio between two colors of the palette. Thanksfully I've already got a few color gradient functions I used to build my palettes so this is as good as done.

But the part about how the floating point iteration number is calculated, I've got absolutely no idea what is going on. I *could* just copy the code and it would probably work, but if I don't understand what I'm doing, there's no point. I like maths but I never could understand the type of formula used on the wiki page.

Does anyone understand what's going on here? Could you reformulate how we're calculating the floating point iteration number in a way a beginner at maths like me could understand?

Thanks!  ^-^

Linkback: https://fractalforums.org/index.php?topic=4597.0

Offline claude

  • 3f
  • ******
  • Posts: 2161
    • mathr.co.uk
Re: Can anyone help me understand smooth coloring
« Reply #1 on: January 13, 2022, 04:45:40 PM »
pick a radius R > 2, then |Z| > R implies that |Z^2 + C| > |Z| and more generally that |Z| -> infinity, this gives R the name escape radius.  proof is on math.stackexchange.com somewhere

now suppose R is large, and n is the first iteration where |Z_n| > R.

consider what happens when |Z_n| increases as you move the point C a bit further from the Mandelbrot set boundary.

eventually |Z_n| > R^2, but then |Z_{n-1}| > R, so the iteration count should be n - 1.

for smoothing, we want a value to add to n that is 0 when |Z_n| = R and -1 when |Z_n| = R^2.

taking logs, get log |Z| is between log(R) and 2 log(R)

taking logs again, get log log |Z| is between log log R and log log R + log 2

dividing by log 2, get log_2 log |Z| is between log_2 log R and log_2 log R + 1

subtracting log_2 log R gives (log_2 log |Z| - log_2 log R) is between 0 and 1

negating it gives a value between 0 and -1, as desired

so the smooth iteration count is  n - (log_2 log |Z| - log_2 log R)

(replace 2 by P if you do Z^P + C)

see also http://linas.org/art-gallery/escape/escape.html  which makes a value independent of R, but that is not so useful for some colouring algorithms (e.g. smooth part of escape count doesn't align with angle of final iterate)

Offline Modinstaller

  • Fractal Freshman
  • *
  • Posts: 7
Re: Can anyone help me understand smooth coloring
« Reply #2 on: January 13, 2022, 08:14:05 PM »
Alright so, a few things here! (first off, I found https://www.iquilezles.org/www/articles/mset_smooth/mset_smooth.htm which is... hard to understand, but helps a bit)

First of all I tried playing with my escape radius. It had been 2 this whole time, but by thinking about it I realized some julia sets were cut, or totally invisible, which makes sense with big C values. I changed it to 2^64, because why not, expecting it would really lengthen my rendering time, but it didn't (which also makes sense when I think about it - it only adds a couple iterations since squaring blows up so quickly), and it fixes the extreme julia sets, but is quite useless for mandelbrot and still adds a bit of rendering time. Now I'm wondering how to properly fix my julia sets rather than set an absurdly big escape radius  :fp:

Then, about the actual topic of color smoothing:
When I look at the last |Z| with an escape radius of 2, it's not necessarily between 2 and 4. It blows up to really big numbers with really a really big C, which makes sense (and it's not interesting anyway since I'm so far from the mandelbrot shape). If I subtract C to it, I get something less than 4, which also makes sense, since it's something less than 2 squared. But it's between 0 and 4, not 2 and 4. Sometimes it's < 2 and C brings it beyond 2. But if I bring C back into it, then it goes beyond 4 too. I must be missing something here.

Finally, assuming I can get a number to something between 2 and 4 (or R and R²) to decide how close it is to the last or next iteration (and I get the logic of it), what's bothering me is all these logs. I'd ideally want to understand all the math behind this. All I know about logs (and I had to refresh on that because I forgot *everything* from school lmao) is that it's a sort of reverse exponential where log(n)=x in base b means b^x = n. I'll continue working the math out on my own (or trying to..) to understand the log thing, but I'd appreciate some help!
« Last Edit: January 13, 2022, 09:57:03 PM by Modinstaller »

Offline Alef

  • Fractal Frogurt
  • ******
  • Posts: 496
  • a catalisator / z=z*sinh(z)-c^2
    • My deviant art page
Re: Can anyone help me understand smooth coloring
« Reply #3 on: January 13, 2022, 08:19:44 PM »

Bailout value must be mutch larger than 2 or 4 for this to be smooth. 128 is a bare minimum. It's almoust the more the smoother (there are other smooth colour methods, and the more advanced the larger escape radius it needs.)
by Edgar Malinovsky aka Edgars Malinovskis.

Offline gerrit

  • 3f
  • ******
  • Posts: 2538
Re: Can anyone help me understand smooth coloring
« Reply #4 on: January 13, 2022, 10:34:46 PM »
help with smooth colors!
For continuous iterations in the more general case see this thread

Offline Modinstaller

  • Fractal Freshman
  • *
  • Posts: 7
Re: Can anyone help me understand smooth coloring
« Reply #5 on: January 14, 2022, 12:20:51 AM »
I implemented it just to see if it'd work and it does - but I don't understand what I just did, so I'm gonna keep on trying to figure it out.

Old :

New :

Offline gerson

  • 3c
  • ***
  • Posts: 840
Re: Can anyone help me understand smooth coloring
« Reply #6 on: January 18, 2022, 02:47:59 PM »
I can't help, but keep trying, the result is very good. More options for your program...