/****************************************************************************
 * This formula file or any formula file derived from it cannot be used for
 * commercial purposes or to create hard copy output without the explicit
 * consent of the original author.
 ****************************************************************************/

fractal {

   // Establish the mapping between complex coordinates
   // and display coordinates

   mapping {
      (-0.07486481584959656100,
       0.44207805458551236000,
       0.22105610477577217000,
       0.67181275975864463000) => (1228,960)
   }

   formula {
     
      z = current;
      zold = [0, 0];

      $xmax = 0;
      $xmin = 0;
      $xtot = 0;
      $ymax = 0;
      $ymin = 0;
      $ytot = 0;
      $mmax = 0;
      $mmin = 0;
      $mtot = 0;
     
      $stop = 0;
      $tolerance = 1e-10;

      while($stop == 0 && $count < 20)
      {
         if(abs(real(z) - real(zold)) <= $tolerance &&
            abs(imag(z) - imag(zold)) <= $tolerance)
         {
            $stop = 1;
         }
         else
         {
            v    = log(z);
            f_z  = log(v);
            fp_z = 1/(v*z);

            zold = z;
            z    = z - fp_z / f_z;

           
            v  = z;
            $x = real(v);
            $y = imag(v);
            $m = old_rad(v);

            $xtot = $xtot + $x;
            $ytot = $ytot + $y;
            $mtot = $mtot + $m;

            $xmax = max($xmax, $x);
            $xmin = min($xmin, $x);

            $ymax = max($ymax, $y);
            $ymin = min($ymin, $y);

            $mmax = max($mmax, $m);
            $mmin = min($mmin, $m);
         }
      }

      $r = 0;
      $g = 0;
      $b = 0;

      if($count > 0)
      {
         $r = (($xtot / $count) - $xmin) / ($xmax - $xmin);
         $b = (($mtot / $count) - $mmin) / ($mmax - $mmin);
         $g = (($ytot / $count) - $ymin) / ($ymax - $ymin);

         $r = get_sin_color($r, 150, 1.5);
         $g = get_sin_color($g, 200, 2);
         $b = get_sin_color($b, 0, 1);
      }

      set_color($r, $g, $b);
   }
}















