/****************************************************************************
 * 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 {
      (62.66666666666666429819,
       0.00000000000000000000,
       188.00000000000000000000,
       129.33333333333334280724) => (931,960)
   }




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

      $first = 0;

      $zxmin = 0;
      $zxmax = 0;
      $zymin = 0;
      $zymax = 0;
      $zxtot = 0;
      $zytot = 0;

      $cxmin = 0;
      $cxmax = 0;
      $cymin = 0;
      $cymax = 0;
      $cxtot = 0;
      $cytot = 0;

      while($count < 20 && ssq(z) < 1e10 && ssq(c) < 1e10)
      {
         $zx = real(z);
         $zy = imag(z);
         $cx = real(c);
         $cy = imag(c);

         if($first == 0)
         {
            $first = 1;
            $zxmin = $zx;
            $zxmax = $zx;
            $zymin = $zy;
            $zymax = $zy;

            $cxmin = $cx;
            $cxmax = $cx;
            $cymin = $cy;
            $cymax = $cy;
         }
         else
         {
            if($zx > $zxmax) { $zxmax = $zx; }
            else             { if($zx < $zxmin) { $zxmin = $zx; } }

            if($zy > $zymax) { $zymax = $zy; }
            else             { if($zy < $zymin) { $zymin = $zy; } }

            if($cx > $cxmax) { $cxmax = $cx; }
            else             { if($cx < $cxmin) { $cxmin = $cx; } }

            if($cy > $cymax) { $cymax = $cy; }
            else             { if($cy < $cymin) { $cymin = $cy; } }
         }

         $zxtot = $zxtot + $zx;
         $zytot = $zytot + $zy;
         $cxtot = $cxtot + $cx;
         $cytot = $cytot + $cy;

      
         z = sqrt(c - conj(z));
         c = c + sin(z) * cos(z);
      }

      $red   = 0;
      $green = 0;
      $blue  = 0;

      if($count > 0)
      {
         $diff    = ($zxmax - $zxmin);
         $zxValue = (($zxtot / $count) - $zxmin) / $diff;
         $diff    = ($zymax - $zymin);
         $zyValue = (($zytot / $count) - $zymin) / $diff;

         $diff    = ($cxmax - $cxmin);
         $cxValue = (($cxtot / $count) - $cxmin) / $diff;
         $diff    = ($cymax - $cymin);
         $cyValue = (($cytot / $count) - $cymin) / $diff;

         $red   = ($zxValue) * 255;
         $green = ($zyValue) * 255;
         $blue  = (1 + cos($cxValue)) * 127.5;        
      }

      set_color(255 - $red, $green, $blue);
   }
}

















