Blender Cycles OSL: Mandelbrot Fractal
Hi. Today I'm going to show you an OSL code to get a Mandelbrot Fractal , like this: This fractal uses the following complex numbers formula: Z(n+1) = Z(n) ^ 2 + C I have parameterized the exponent of the formula and the bailout value, that is, the value to stop the iterations. So the code is this : shader mandelbrot_fractal_zn_zoom( float Scale = 1.0, float Zoom = 3.5, vector Vector = (vector)P, float CenterX = 0.0, float CenterY = 0.0, int MaxIterations = 64, int Exponent = 2, float Bailout = 2.0, output float Fac = 0.0) { point p = (point)Vector*Scale/(2*Zoom); int i = 0; int j = 0; int prevIteration = MaxIterations; float factor = 0.0; float foo = 0.0; // Starting point p[0] += CenterX; p[1] += CenterY; // Initialize point pa = point(0.0); point pb = point(0.0); point pc = point(0.0); // Mandelbrot algorithm do { // z^j for(j = 1; j B...