/****************************************************************************
 * 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.02340000000000010000,
       -2.01344898802147880000,
       4.33446227347611130000,
       2.02666666666666680000) => (1276, 960)
   }

   formula
   {
      // Here we just need 2 points that we'll be integrating between ...

      pStart = csc(current);
      pEnd   = exp(current);

      // The number of slices we'll break up the integral between
      // pStart and pEnd into ...

      $steps = 20;

      // variables to record color information

      $v1min = 0; $v2min = 0; $v3min = 0;
      $v1max = 0; $v2max = 0; $v3max = 0;
      $v1tot = 0; $v2tot = 0; $v3tot = 0;

      // zstep is the amount we'll move z by
      // as we traverse the slices.

      zstep = (pEnd - pStart) / ($steps + 1);
      z     = pStart;

      // Loop through all the slices

      while($count < $steps)
      {
         // Get the next 'z' point

         znext = z + zstep;

         // Find the height of the left and right sides
         // of the trapezoid for the first function

         f1Left  = sec(z) - csc(z);
         f1Right = sec(znext) - csc(znext);

         // Calculate the area of the trapezoid ...

         f1Area = (f1Left + f1Right) * zstep / 2;

         // Now find the height of the left and right sides
         // of the trapezoid for the second function

         f2Left  = sin(z)^2 - cos(z);
         f2Right = sin(znext)  - cos(znext)^2;

         // Calculate the area of the trapezoid ...

         f2Area = (f2Right - f2Left)  * zstep /2;

         // Calculate the difference between the 2 areas

         diff = f2Area - f1Area;       

         // Color assignment

         value = log(diff);

         $x   = mag(value^2);
         $y   = mag(value^6);
         $m   = mag(value^18);

         $v1min = min($v1min, $x);
         $v2min = min($v2min, $y);
         $v3min = min($v3min, $m);

         $v1max = max($v1max, $x);
         $v2max = max($v2max, $y);
         $v3max = max($v3max, $m);

         $v1tot += $x;
         $v2tot += $y;
         $v3tot += $m;

         z = znext;
      }

      $b = ($v1tot / $count - $v1min) / ($v1max - $v1min);
      $g = ($v2tot / $count - $v2min) / ($v2max - $v2min);
      $r = ($v3tot / $count - $v3min) / ($v3max - $v3min);

      $r = get_sin_color($r, 255, 1);
      $g = get_sin_color($g, 255, 1);
      $b = get_sin_color($b, 255, 1);

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
















