/****************************************************************************
 * 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 {
      (-15.71300967918759800000,
       -17.64888651935146400000,
       18.75753336721200500000,
       17.72184677039749800000) => (1228,960)
   }

   // Initialize our color table, here we have two color ranges - the
   // first a series of purple colors, the second a series of yellow colors

   colors {
      define(0){
         gradient(361) {
            [51 0 51]
            [204 204 255]
            [51 0 51]
         }
      }
      define(360){
         gradient(361) {
            [255 255 204]
            [204 153 0]
            [255 255 204]
         }
      }
   }

   // Set up our fractal

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

      // Our stopping condition is pretty traditional, though the equation
      // we used:
      //
      // z = (1/c) ^ z
      //
      // (z = 1/c raised to the z power) is a bit out of the ordinary

      while($count < 100 && magnitude(z) < 2)
      {
         z = pow(1/c, z);
      }
 
      // We use: fmod($count, 2) * 360 to select between the yellow and
      // magenta sets of colors. This results in:
      //
      // fmod($count, 2) * 360 = 0   (if $count is even, we'll get a purple
      //                              color shade)
      // fmod($count, 2) * 360 = 360 (if $count is odd, we'll get a yellow
      //                              color shade)
      //
      // The specific color selected is calculated via:
      //
      // abs(cos(magnitude(z))) * 360
      //
      // magnitude(z) is the distance of z from the origin (this value might
      // be anything) but by taking the cos, we ensure the result is between
      // -1 and 1.  Taking the absolute value of that number we get a result
      // between 0 and 1 and finally multiplying by 360 produces a value that
      // spans the entire range of 360 entries within the chosen set of
      // colors.

      set_color(
         fmod($count, 2) * 360 + abs(cos(magnitude(z))) * 360
      );
   }
}











