Question

I made a program to calculate points that are in the mandelbrot set. For the points not belonging to the mandelbrot set I keep track of how many iterations it take for the starting point to diverge to where the magnitude is greater that 2. Basically for every point not in the mandelbrot set I have a counter of how fast it diverges on a scale of 1 to 256. What id like to do is give each point a color according to how fast it diverges. For instance the points that diverge in 255 iterations could be white and the faster it diverges the more it gets colored. I've made an easy adjustment where diverging points that diverge in more than 20 steps are colored red, the ones that diverge in 10-19 steps are blue and one that diverge in 5-9 steps are yellow and it looks like this.

enter image description here

Now I cant do this for all possible 255 rates of divergence. How can I make a graduating scale and implement it in Matlab. Thanks in advance for any help. If anyone would like to know any more please ask. Thanks!

EDIT I am sorry but the image seems to not work. Basically what I need it this. I am plotting points, to each point a value between 1 and 255 is assigned and I want the color to gradually change depending on the value assigned to it. Thanks!

Was it helpful?

Solution

A simple approach to plotting the mandelbrot set in Matlab is as follows

function mandelbrot(n, niter)

x0 = -2;   x1 = 1;
y0 = -1.5; y1 = 1.5;

[x,y] = meshgrid(linspace(x0, x1, n), linspace(y0, y1, n));

c = x + 1i * y;
z = zeros(size(c));
k = zeros(size(c));

for ii = 1:niter
    z   = z.^2 + c;
    k(abs(z) > 2 & k == 0) = niter - ii;
end

figure,
imagesc(k),
colormap hot
axis square

This just keeps track of the number of iterations until divergence in the array k, and plots it using a linear color scale by using imagesc. The result is

>> mandelbrot(800, 40)

enter image description here

OTHER TIPS

The image doesn't come in the link and I don't know Matlab, but can you not make the color of each point a function of its divergence? A lot of tools will allow you to specify RGB values, say, from 0-255. Can you not input its divergence for all three RGB values (or whatever color scale you're using) to get shades of gray? i.e. RGB(20,20,20)

I did a little improvement to the code, this will now run given a specific starting point for (x,y) and a starting position. For those looking to zoom in a little further.

function mandelbrot(n, n2, x0, y0, g)

x1 = x0 - g;   x2 = x0 + g;
y1 = y0 - g; y2 = y0 + g;

[x,y] = meshgrid(linspace(x1, x2, n), linspace(y1, y2, n));

c = x + 1i * y;
z = zeros(size(c));
k = zeros(size(c));

for ii = 1:n2
    z   = z.^2 + c;
    k(abs(z) > 2 & k == 0) = n2 - ii;
end

figure,
imagesc(k),
colormap hot
axis square
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top