Fractal smooth Mandelbrot coloration with continuous search array
I know there have been several questions already asked about Mandelbrot fading techniques (and answered). However, none of them describe how to build an array of continuous colors in regular C.
I read extensively about anti-aliasing color algorithms and I can calculate a continuous number of iterations with the main exit time algorithm. I mainly use this number to manually install the color reba components. (Please don't suggest that I use OPENGL or the like ... I just want to do it manually because I want to understand it).
here is my code:
#define W 800 //window width
#define H 800 //window height
#define MAX_ITERS 1000 // number of iterations
union color_u
{
unsigned int num; //color as an integer
unsigned char comp[4]; //color as components (brga) -> beacause of the endianness
};
unsigned int getColor(int i, double *z)
{
double k;
color_u color;
k = i + 1 - log(log(sqrt(z[R] * z[R] + z[I] * z[I]))) / log(2);
k /= MAX_ITERS;
if (i > 700)
{
color.comp[0] = (unsigned char) (255.0 * k); //blue
color.comp[1] = (unsigned char) 0; //green
color.comp[2] = (unsigned char) 0; //red
color.comp[3] = (unsigned char) 0; //alpha
}
else
{
color.comp[0] = (unsigned char) 0; //blue
color.comp[1] = (unsigned char) 0; //green
color.comp[2] = (unsigned char) (255.0 * k) //red
color.comp[3] = (unsigned char) 0; //alpha
}
return color.num;
}
void mandelbrot(void)
{
int i;
double z[2];
double c[2];
double tmp;
c[R] = fr->x + (pixel[X] - W) / (e->zoom * W);
c[I] = fr->y + (pixel[Y] - H) / (e->zoom * H);
z[R] = 0;
z[I] = 0;
i = 0;
while (z[R] * z[R] + z[I] * z[I] < 4 && ++i < MAX_ITERS)
{
tmp = z[R] * z[R] - z[I] * z[I] + c[R];
z[I] = 2 * z[R] * z[I] + c[I];
z[R] = tmp;
}
if (i < MAX_ITERS)
{
draw_pixel(getColor(i, z));
}
}
The result is great, but not amazing.
Now I would like to build a pre-computed array of continuous colors with size MAX_ITERATIONS
... to use mine i
as an index and lookup in the table.
However, I cannot figure out how to do this. Almost everyone uses functions to do it in Java or C ++, but I would like to create it myself.
thank
source to share