/****************************************************************************
 * 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 {
      (-1.84749083803919900000,
       2.60041085816203750000,
       -1.84536402339803330000,
       2.60312968683660270000) => (749,960)
   }

   formula
   {
      z          = current;
      c          = current;
      $stop      = 0;
      $xMin      = 0;
      $xMax      = 0;
      $xTot      = 0;
      $yMin      = 0;
      $yMax      = 0;
      $yTot      = 0;
      $mMax      = 0;
      $mMin      = 0;
      $mTot      = 0;

      while($stop == 0 && $count < 20)
      {
         $x = real(z);
         $y = imag(z);
         $m = mag(z);

         $xTot = $xTot + $x; $xMin = min($xMin, $x); $xMax = max($xMax, $x);
         $yTot = $yTot + $y; $yMin = min($yMin, $y); $yMax = max($yMax, $y);
         $mTot = $mTot + $m; $mMin = min($mMin, $m); $mMax = max($mMax, $m);

         // Get degrees of z, mod 90 (which makes all 4 quadrants the same)

         $d = fmod(old_deg(z), 180);

         // If the angle of z falls within 10 degrees of the midpoint of
         // the 90 degree section ...

         if($count > 0 && $d > 89 && $d < 91)
         {
            $stop = 1;
         }
         else
         {
            z = sec(sin(-z)) + csc(sin(c));
            //c = c * z;
         }
      }

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

      if($count > 0)
      {
         $xValue = (($xTot / $count) - $xMin) / ($xMax - $xMin);
         $yValue = (($yTot / $count) - $yMin) / ($yMax - $yMin);
         $mValue = (($mTot / $count) - $mMin) / ($mMax - $mMin);

         $r = get_sin_color($xValue, 255, 1);
         $g = get_sin_color($yValue, 200, 1);
         $b = get_sin_color($mValue, 255, 1);

         if($r == 0 && $g == 0 && $b == 0)
         {
            $r = 7;
            $g = 100;
            $b = 4;
         }        
      }

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

   }
}
























