/****************************************************************************
 * 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 {
      (-2.20000000000000020000,
       -2.20000000000000020000,
       2.20000000000000020000,
       2.20000000000000020000) => (959,960)
   }

   formula {

      z = current;

      $minValue = 0;
      $maxValue = 0;
      $total    = 0;

      p = [0.238498, 0.519198]; 

      while($count < 50 && ssq(z) < 16)
      {
         z = z ^ 2 + p;

         // Some variations:
         //
         //    zValue = z ^ z;
         //    zValue = cosh(z);
         //    zValue = sec(z);
         //    zValue = sec(z) ^ csc(z);
         //    zValue = cos(z);
         //    zValue = z;

         zValue = z ^ z;
         $angle = deg(zValue);
         p      = rotate(p, [0, 0], $angle);
         $value = mag(cot(z));

         $minValue = min($value, $minValue);
         $maxValue = max($value, $maxValue);
         $total    += $value;
      }

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

      if($count > 0)
      {
         $r = (($total / $count) - $minValue) / ($maxValue - $minValue);
         $r = get_sin_color($r, 205, 1);

         $g = $r;
         $b = $r;
      }

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







