fractal 
{
  mapping {
      (-2,
       -2,
        2,
        2) => (292, 240)
   }




  formula 
  {
    c = current;
    z = current;

    // z    = z^3   + c*z^2 - 1;  // the function
    // z'   = 3*z^2 + c*2*z;      // 1st derivative
    // z''  = 6*z   + c*2;            // 2nd derivative
    // 6*z + 2*c = 0;
    // z     = -c/3;

    z = -z/3;

    z1 = 1;
    maxit = [64, 0];
    z2 = [0,0];

    $xtot = 0;
    $ytot = 0;

    xtmp = [0, 0];
    ytmp = [0, 0];
    trap = [0.1, 0];
    
    while ($count < real(maxit) && sum_of_squares(z1-z) > 1e-24)
    {
  
      z1 = z;      
      z2 = z*z;
      z = z - (z*z2 + c*z2 - 1)/(3*z2 + 2*c*z);

      xtmp = [abs(real(z)), 0];
      if (real(xtmp) < real(trap))
      {
        $xtot = $xtot + (1 - real(xtmp)/real(trap));   
      }

      ytmp = [abs(imaginary(z)), 0];
      if (real(ytmp) < real(trap))
      {
        $ytot = $ytot + (1 - real(ytmp)/real(trap)); 
      }

    }

    $const2PI = 6.28318;

    // "Start" Color variables should be in range from 0 to 255
    $red_Start = 255;
    $grn_Start = 255;
    $blu_Start = 255;

    // "Step" Color variables should be in range from 0 to about 2
    $red_Step = 0.7;
    $grn_Step = 0.6;
    $blu_Step = 0.5;

    // Sine function Coloring algorithm starts here
    $r = sqrt($xtot);
    $g = sqrt($ytot);
    $b = ($r+$g)*0.5;
    $g = ($g+$b)*0.5;  // make it a bit of gray scale

    $t1 =  -sin($const2PI*$r);
    $t2 =  -cos($const2PI*$g);
    $t3 =  -cos($const2PI*$b);

    $t1 = $t1*127+127;
    $t2 = $t2*127+127;
    $t3 = $t3*127+127;

    $t1 = $t1*$red_Step+$red_Start;
    $t2 = $t2*$grn_Step+$grn_Start;
    $t3 = $t3*$blu_Step+$blu_Start;

    $t1 = $t1/360;
    $t2 = $t2/360;
    $t3 = $t3/360;

    $r =  sin($const2PI*$t1);
    $g =  sin($const2PI*$t2);
    $b =  sin($const2PI*$t3);

    $red = ($r*128) + 127;
    $grn = ($g*128) + 127;
    $blu = ($b*128) + 127;

    //  the new coloring function

    if ($xtot == 0 && $ytot == 0)
    {
      set_color ( 000, 000, 000 );
    }
    else
    {
      set_color ( $red, $grn, $blu );
    }
  }
}







