/****************************************************************************
 * 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.16321551983173200000,
       -4.10192418981480690000,
       3.00363769531249770000,
       4.04963831018519200000) => (720,960)
   }

   // Set up our colors - here we use 3 sets of colors, the first
   // will contain shades of yellow, the second: shades of green and
   // the last: shades of cyan

   colors {
      define {
         gradient(361) {
            [255 255 204]
            [204 153 0]
            [255 255 204]
           
         }
      } 
      define {
         gradient(361) {
            [204 255 204]
            [0 51 0]
            [204 255 204]
         }
      }
      
      define {
         gradient(361) {
            [204 255 255] 
            [0 51 51]
            [204 255 255]
         }
      }
   }
   
   // Set up our fractal

   formula {

      // Initialize variables

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

      // Stopping condition

      while($count < 100 && magnitude(z) < 4)
      {
         // Formula for iteration, it is worth noting that fractals
         // using this type of equation:
         //
         //    value1 = log(something)
         //    value2 = exp(something)
         //
         // frequently produce very interesting results

         z = log(z + c);
         c = exp(z + c);
      }

      // The first portion: fmod($count, 3) * 360 lets us select between
      // the yellow, green and cyan sections of our color table.  If
      // $count is divisible by 3 fmod($count, 3) * 360 will be zero (and
      // we're selecting the yellow section), if $count divided by 3 leaves
      // a remainder of 1 then fmod($count, 3) * 360 = 360 (and we're selecting
      // the green section), if $count divided by 3 leaves a remainder of
      // 2 fmod($count, 3) * 360 = 720 (and we're selecting the cyan section)
      //
      // To select the index within the section, we know that:
      // -1 <= sin(radians(z)) <= 1 so: 0 <= abs(sin(radians(z))) <= 1
      // which we multipy by 360 to be able to span all 360 entries within
      // our chosen section

      set_color(fmod($count, 3) * 360 + abs(sin(old_rad(z))) * 360);
   }
}
