fractal 
{
  mapping {
      (-2,
       -2,
        2,
        2) => (320, 240)
   }


  colors 
  {
    define 
    {
      gradient(361) 
      {
        [255 255 255] [000 064 124] [128 120 000]
      }
    }
  }

  formula 
  {
    c     = current;
    LSum  = current;
    LSum1 = [1,0];
    maxit = [20, 0];
    LVal  = 0;

    K     = 0.133;  // Constant
    P     = 1;    // Population

    temp = 0;
    
    while ($count < real(maxit) && sum_of_squares(LSum1 - LSum) > 1e-14)
    {        
      LSum1 = LSum;
      LSum = LSum * 2 * (K-2*K*P-3*K*P*P);  // the derivative
      temp = [fmod($count, 4), 0];

      if (real(temp) == 0)
      {
        K = real(c);
      }       

      if (real(temp) == 1)
      {
        K = real(c);
      }       

      if (real(temp) == 2)
      {
        K = imaginary(c);
      }     

      if (real(temp) == 3)
      {
        K = imaginary(c);
      }       

      //K = K+sin(3*K-sin(K));

      P = K*P-K*P*P-K*P*P*P;

      //P = K*P-K*P*P;
      //LSum = LSum * 2 * (K-2*K*P-3*K);  // the derivative

      if ($count > 1)
      {
        if (abs(real(LVal)) < 1e3)
        {
          LVal = LVal + 1/(1+LSum);
        }
      }
    }

    //$color   = $count*(360/real(maxit));
    set_color ( 10*real(LVal));
  }
}




