Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandelbrot set smooth colouring function

I programmed the Mandelbrot set with python but that was weird looking so I searched for smooth colors. I've programmed a smooth colouring function using log and linear interpolation but whatever I try I can't get what I want:

self.palette = [(3, 25, 61),(5, 43, 107),(7, 61, 153),(20, 96, 226),(20, 164, 226),(74, 181, 226),(138, 211, 242),(205, 234, 247),(225, 237, 242),(255,255,255)]

Here is my palette

if n == self.max_iterations:
    self.screen.set_at((x, y), (110, 13, 13))
else:
    gradient = 1 + n - math.log(math.log(abs(m))) / math.log(2.0)
    iteration = n + 1 - gradient
    color1 = list(self.palette[n % 10])
    if n % 10 <= 8:
        color2 = list(self.palette[n % 10+1])
    else:
        color2 = list(self.palette[-1])

    color = [[], [], []]
    for number, elt in enumerate(color):
        color[number] = color1[number] + (iteration % 1)*(color2[number]-color1[number])

    self.screen.set_at((x, y), tuple(color))

Here my colouring function

And here what I get

As you can see colors are smooth but in the wrong way there is no continuity in the colors

I would like to have something like this :

ideal result

we do not see color gaps

like image 508
Hugo Avatar asked Oct 29 '25 07:10

Hugo


1 Answers

It looks like you're selecting the pixel-color based on a discrete value (n, the escape-time).

I would suggest:

1) Plot your color-vs.-n on a 1D line. Does it appear continuous? If not, choose a color-map that appears continuous w.r.t. increasing n.

2) Find a way to make n continuous, not discrete. One way to do this is by calculating your max-escape-time for the viewing window, and then dividing all other escape-times by this value, to yield a more continuous field. See this link on escape-time normalization:
https://linas.org/art-gallery/escape/escape.html

I believe if you meet both of the above criteria, the field surrounding the main image will appear continuous instead of having the 'iso-line' appearance.

like image 83
afarley Avatar answered Oct 31 '25 00:10

afarley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!