/****************************************************************************
 * 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.57720801228803797489,
       5.59458035470382686327,
       0.64791334136706280056,
       5.68555722286142639632) => (357, 457)
   }

   formula {
     
      z = current;      

      $amax = 0; $amin = 0; $atot = 0;
      $bmax = 0; $bmin = 0; $btot = 0;
      $cmax = 0; $cmin = 0; $ctot = 0;
     
      $stop      = 0;
      $d      = 0;
      $tolerance = .1;

      while($count < 21 && $stop == 0)
      {     
         $power = 2;

         z = log(pow(z, $power)) * pow($power, z);

         if(ssq(z - [0, 0])      < $tolerance) { $d = ssq(z - [0, 0]); $stop = 1; }
         elseif(ssq(z - [2, 0])  < $tolerance) { $d = ssq(z - [2, 0]); $stop = 1; }
         elseif(ssq(z - [-2, 0]) < $tolerance) { $d = ssq(z - [-2, 0]);$stop = 1; }
         elseif(ssq(z - [0, 2])  < $tolerance) { $d = ssq(z - [0, 2]);$stop = 1; }
         elseif(ssq(z - [0, -2]) < $tolerance) { $d = ssq(z - [0, -2]);$stop = 1; }
         elseif(abs(real(z))     < $tolerance) { $d = abs(real(z)); $stop = 1; }
         elseif(abs(imag(z))     < $tolerance) { $d = abs(imag(z)); $step = 1; }
         else
         {
     
            $a = real(z);
            $b = imag(z);
            $c = mag(z);

            $atot = $atot + $a;
            $btot = $btot + $b;
            $ctot = $ctot + $c;

            $amax = max($amax, $a);
            $amin = min($amin, $a);

            $bmax = max($bmax, $b);
            $bmin = min($bmin, $b);

            $cmax = max($cmax, $c);
            $cmin = min($cmin, $c);
         }
      }

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

      if($count > 0)
      {
      
         $r = (($atot / $count) - $amin) / ($amax - $amin);
         $g = (($btot / $count) - $bmin) / ($bmax - $bmin);
         $b = (($ctot / $count) - $cmin) / ($cmax - $cmin);
                 
         $factor = 1;

         if($stop == 1) { $factor = $d / $tolerance; }

         $r = get_sin_color($r, 255, $factor);
         $g = get_sin_color($g, 255, $factor);
         $b = get_sin_color($b, 255, $factor);
      }

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


















