Search code examples
javajavascriptfractalsmandelbrot

I can't understantd something about mandelbrot fractal code


It is calculation function code. I heard "escape" should be 4(2^2). because if (z_r*z_r + z_i*z_i) is smaller than 4 it won't go infinity. but in this code escape is 1025^2. why ? why 1025^2?

function computeRow(task) {
var iter = 0; //iteration
var c_i = task.i; //
var max_iter = task.max_iter; // = 1024
var escape = task.escape * task.escape; //task.escape=1025
task.values = [];
for(var i = 0; i <task.width;i++) {
    var c_r = task.r_min+(task.r_max - task.r_min) * i/ task.width;
    var z_r = 0, z_i = 0;

    for(iter = 0; z_r*z_r + z_i*z_i < escape && iter < max_iter; iter++) {
        // z->z^2 + c                   ▲ i wonder about this
        var tmp = z_r*z_r - z_i*z_i + c_r;
        z_i = 2*z_r*z_i+c_i;
        z_r = tmp;
    }
    if(iter == max_iter) {
        iter = -1;
    }
    task.values.push(iter);
}
return task;}

Solution

  • I heard "escape" should be 4(2^2)

    Escape radius should be greater then 2 so any value > 2 is good. It can change shape of level sets and shape of numerical aproximation of Mandelbrot set. Square of escape radius should be greater then 4.

    See also this question

    HTH