Entradas

Mostrando las entradas etiquetadas como mandelbrot

Blender Cycles OSL: Mandelbrot Fractal

Imagen
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...

Blender Cycles OSL: Mandelbrot Fractal (Interior Colors)

Imagen
Hi. Today I'm going to show you an OSL code to get a Mandelbrot Fractal with its interior colorized, like this: You can see a HiRes version in this link . This is the code: #include <stdosl.h> shader node_fractal( float CenterX = 0.0, float CenterY = 0.0, point Vector = P, float Zoom = 1.0, int MaxIterations = 50, color Foreground = color(1.0), color Background = color(0.0), output float Fac = 0.0, output color Color = 0.0) { point p = Vector / (2* Zoom); float auxiliar = 0.0; p[0] += CenterX; p[1] += CenterY; point pa = p; point pb = point(0.0); int i = 0; for(i=1; i<MaxIterations; i++) { pb[0] = pa[0]*pa[0] - pa[1]*pa[1]; pb[1] = pa[0]*pa[1] + pa[1]*pa[0]; pa = pb + p; } auxiliar = sqrt((pa[0]*pa[0]) + (pa[1]*pa[1])); Fac = clamp(auxiliar,0.0,1.0); if (Fac == 0.0) Color = Background; else Color = mix(Foreground, Background, ...