1

Looking for trainings on python I decided to draw the mandelbrot set using a script. Drawing it wasn't too complicated so I decided to use color and I discovered the smooth coloring algorithm. Using this question I was able to render something really beautiful and similar to this one.

To achieve that I set up a gradation color palette using three "steps" : From dark blue to light blue, then light blue to yellow and finally yellow to dark brown. The overall image is perfect.

Problem comes when I try too zoom in. Let's take the example of this area. When I'm at this level of zoom, my script doesn't draw dark blue anymore. I think I mis coded something because whereever you see dark blue on the wikipedia image, I have dark brown (so a color near the end of my palette). When I first thought about this I told myself if the pattern is going back to the original one, then it should use the same colors cause escape time should be the same.

So, was this coloring configured in the palette or is there something about escape time I didn't understand ?

Here is the code I use for the coloring :

def color_pixel(n, z):
    smoothcolor = n + 1 - math.log(math.log(abs(z)))/math.log(2)
    f = smoothcolor/iterate_max
    i = int(f*500)
    color = palette[i]
    return color

500 is the number of colors in my palette (len(palette)-1).

z the value of z when it escaped over 10.

I use 100 as the max iterations but same results with a higher value.

Thanks !

sanyassh
  • 8,100
  • 13
  • 36
  • 70
Lich4r
  • 1,305
  • 2
  • 13
  • 27
  • When you zoom in to a small area such as you show, the lowest iteration in the region is no longer 1, so the colours at the low end of the colours array do not get used. OTOH at the base level, very few of the colours at the upper end of the array are used, so you don't notice them. One thing you could do, is to find the lowest iterations around the edge of the region before rendering the image, and use that as an offset. – Weather Vane Oct 16 '16 at 14:16
  • The more I zoom the more iterations will get high ? I should do a loop on the palette so the colors come back then ? – Lich4r Oct 16 '16 at 19:11
  • That's right, the low iterations are only at the edge of the first scale image, and your posted image tells you that! When you experiment, you'll find that the deeper the zoom, the more iterations are required to resolve the detail - *in the neighbourhood of the M-set* which typically is wheer you will be to get an interesting image. – Weather Vane Oct 16 '16 at 19:16
  • ...and yes, I use a palette that is indexed by the iteration mod palette size, where the colour wraps smoothly back to index[0]. Although the colouring is purely subjective, it depends what you are trying to do. For a dynamic zoom, the colour of each contour must be always the same. But for a single static image, you need to experiment. For that, not all zoomed regions look good with the same colouring method. – Weather Vane Oct 16 '16 at 19:19
  • ... in some regions of the map, the iteration variation across the image is not as great as other regions. For example, a thread which links the main iconic image to a smaller version of the same. The closer to any of those main or mini M-set shapes you are, the more *range* of iterations you will find. – Weather Vane Oct 16 '16 at 19:24
  • Just tried this by making a loop on the palette. This seems to be the key indeed! However is there a way to know how quick the iteration go up for a specific area. In the wikipedia zoom I linked we can see the blue stop right before the spiral. I can get this with a 140 iterate_max and a dark_blue - light_blue gradation that represents half of the whole palette. Light_blue - yellow and yellow-dark_brown representing each 25%. Whereas I can experiment values I don't understand the link between them. (max iteration, max colors, part of each gradation in the colors) – Lich4r Oct 16 '16 at 20:09
  • Uh, how quick the iteration? At deeper levels this is far more of an issue than how to colour the image, but as I suggested earlier, you will at least know the *minimum* iterations if you traverse the border of the image first. – Weather Vane Oct 16 '16 at 20:46
  • Rotative palette was the answer to my original question so you should add an answer so I can mark it. I was wondering if I can predict how quick the number of iterations needed to escape will go up the more I zoom (ie n in my code). So I can code this zone (one spiral at a given zoom level for example) will start with this color – Lich4r Oct 17 '16 at 08:23

2 Answers2

0

My colouring method is to use a rotative array in three sections. First blue cross-fades to green without using red, then green to red without using blue, and finally red to (almost) blue with no green, where the next iteration level will wrap back to pure blue at the bottom of the array by using a modulus of the iterations.

However when I made a supposedly smoothe realtime zoom (by storing the data with a doubling scale, and then in-betweening 16 frames by interpolation for playback), I found that in the neighbourhood of the M-set, where the contours look chaotic, the effect was messy as the colours tend to dance around. There I used a different scheme, bending the colours to a gray scale.

My final colouring method was to use the rotating palette for pixels having one or more neighbours of the same depth, but tending towards mid-gray depending on how many neighbours were different. Bear in mind though, that the requirements for a moving image are different from a static image, and sharp detail is not necessarily desirable.

At deep zooms the number of iterations needed to extract the detail can be 1000 or more. I solved the problem laterally. I do not brute-force the map calculations. I developed a curve-stitching method that follows the contour of an iteration level, and then fills the region. In the smoothly changing areas that means large areas do not have to be iterated. Similarly for the M-Set itself where the function has not escaped - I avoid iterating there as far as possible by again trying to follow round its edge and then filling. This method can suffer from nipping off some detail, but the speed gain is enormous. In the chaotic region near the edge of the M-Set my method was to just iterate at every pixel.

Weather Vane
  • 33,872
  • 7
  • 36
  • 56
0

I'm also looking into this now as well (the coloring scheme). Since the image was made using Ultra Fractal 3, I looked into that program and poked around and finally found the details, which are slightly different than from what you and the wiki are doing. It's written in some custom scripting language but hopefully you can understand what it's doing. Here's the code:

Smooth(OUTSIDE) {
;
; This coloring method provides smooth iteration
; colors for Mandelbrot and other z^2 formula types
; (Phoenix, Julia).  Results on other types may be
; unpredictable, but might be interesting.
;
; Thanks to F. Slijkerman for some tweaks.
; Thanks to Linas Vepstas for the math.
;
; Written by Damien M. Jones
;
init:
  complex il = 1/log(@power)        ; Inverse log (power).
  float lp = log(log(@bailout))     ; log(log bailout).

final:
  #index = 0.05 * real(#numiter + il*lp - il*log(log(cabs(#z))))

default:
  title = "Smooth (Mandelbrot)"
  helpfile = "Uf*.chm"
  helptopic = "Html/coloring/standard/smooth.html"
$IFDEF VER50
  rating = recommended
$ENDIF

  param power
    caption = "Exponent"
    default = (2,0)
    hint = "This should be set to match the exponent of the \
            formula you are using. For Mandelbrot, this is usually 2."
  endparam
  param bailout
    caption = "Bail-out value"
    default = 128.0
    min = 1
    hint = "This should be set to match the bail-out value in \
            the Formula tab. This formula works best with bail-out \
            values higher than 100."
  endparam
}

My math isn't good enough to know how to compute the log of a complex number so I'm stuck at the moment in going further using this, but I thought I'd share what I've found on this topic.

Jason Hoffoss
  • 81
  • 1
  • 2