Julia set - symatevo/fract-ol GitHub Wiki

The Julia set formula is similar to the Mandelbrot set formula.

For example, the initialization of the variable z in the formulas of these two sets is identical:

The difference between them lies in the main part of the formulas, where in the case of the Julius set, the constant k is used, instead of the variable c in the Mandelbrot set:

According to the text of the assignment, the value of the constant k in our program should be set using the mouse.

In addition to the variables already described in the parsing of the Mandelbrot set, for the Julius set, it is also necessary to initialize the mentioned constant:

k = init_complex (-0.4, 0.6);

To be able to set the value of k with the mouse, we will use the following function:

int julia_motion (int x, int y, t_fractol * fractol)
{
    fractol-> k = init_complex (
        4 * ((double) x / WIDTH - 0.5),
        4 * ((double) (HEIGHT - y) / HEIGHT - 0.5));
    draw_fractal (fractol);
    return (0);
}

The principle of its operation may not be obvious, so we will take a closer look at some of the key points.

If we were to set k with the following lines of code, then the values โ€‹โ€‹of the real and imaginary parts would vary within [0; 1] when moving the mouse cursor within the boundaries of the program window:

fractol-> k = init_complex (
    (double) x / WIDTH,
    (double) (HEIGHT - y) / HEIGHT);

The value of the imaginary part is set in a special way because in the program the y-axis is directed from top to bottom, not from bottom to top. And with this approach, we turn this axis into its usual position.

If you use the above code, then the conditional "equilibrium point" will coincide with the origin point and will be in the lower left corner.

To place it in the center of the program window, you need to shift the coordinate axes by 0.5 below and to the left:

fractol-> k = init_complex (
    (double) x / WIDTH - 0.5,
    (double) (HEIGHT - y) / HEIGHT - 0.5);

Now the possible values โ€‹โ€‹of the real and imaginary parts are in the range [-0.5; 0.5] when moving the mouse within the window.

Multiplying by 4 only increases the range of possible values.

In the code, the Julius set formula will look like this:

iteration = 0;
while (pow (z.re, 2.0) + pow (z.im, 2.0) <= 4
    && iteration <max_iteration)
{
    z = init_complex (
        pow (z.re, 2.0) - pow (z.im, 2.0) + fractol-> k.re,
        2.0 * z.re * z.im + fractol-> k.im);
    iteration ++;
}