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.
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!
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)