Results 1 to 2 of 2
  1. #1
    Member andgarrett's Avatar
    Join Date
    May 2007
    Location
    Michigan
    Posts
    226

    mandelbrot confusion

    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.
    If ignorance is bliss, then wipe the smile off my face.



  2. #2
    Member andgarrett's Avatar
    Join Date
    May 2007
    Location
    Michigan
    Posts
    226
    I just found some insight into the way the code works from the mandelbrot wikipedia page:

    In pseudocode, this algorithm would look as follows. The algorithm does not use complex numbers and manually simulates complex-number operations using two real numbers, for those who do not have a complex data type. The program may be simplified if the programming language includes complex-data-type operations.

    For each pixel (Px, Py) on the screen, do:
    {
    x0 = scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))
    y0 = scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))
    x = 0.0
    y = 0.0
    iteration = 0
    max_iteration = 1000
    while (x*x + y*y < 2*2 AND iteration < max_iteration) {
    xtemp = x*x - y*y + x0
    y = 2*x*y + y0
    x = xtemp
    iteration = iteration + 1
    }
    color = palette[iteration]
    plot(Px, Py, color)
    }

    the script on my above post is clearly derived from this pseudo code. now I just need to figure out how to make a similar script but with julia sets.
    Last edited by andgarrett; 30-Nov-17 at 22:59.
    If ignorance is bliss, then wipe the smile off my face.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •