I'm trying to apply the mandelbrot set to my shader, but I've encountered a road block. first of all, osl doesn't seem to support complex numbers. you can't use pow(-1, 0.5) for example. I found a script that someone else wrote that seems to work, but I can't figure out why, and if I don't understand it, I can't manipulate it. here's is the code that works:

Code:

shader Fractal(
float Hue = 0,
point pos = P,
output color Color = 0
){
int i;
float real = pos[0];
float imag = pos[1];
float x = real;
float y = imag;
real = 0;
imag = 0;
for(i = 0; i < 20; i++) {
float realt = pow(real,2) - pow(imag, 2) + x;
imag = 2*imag*real + y;
real = realt;
if(pow(real,2)+pow(imag,2)>4){
Color = color("hsv", Hue, 1, i/20.0);
break;
}
}
}

looking at this code I see no complex numbers. it doesn't have anything in the form y = z^2 + c.

## Bookmarks