title: Implementing a smooth color algorithm into my existing Mandelbrot generator
body: <p>I am currently writing a Mandelbrot generator, and stumbled onto a smooth color algorithm that creates a, as its name suggests, a "smooth color" as opposed to the example I currently have.</p>
  
  <p><img src="https://i.stack.imgur.com/D2O3G.png" alt="enter image description here"></p>
  
  <p>As you can see, the edge cases are very evident and non-smooth. </p>
  
  <p>Here is my <code>drawFractal()</code> method:</p>
  
  <pre><code>public static void drawFractal()
  {
      Complex Z;
      Complex C;
  
      double x;
      double y;
  
      // The min and max values should be between -2 and +2
      double minX = -2.0; // use -2 for the full-range fractal image
      double minY = -2.0; // use -2 for the full-range fractal image
      double maxX = 2.0; // use 2 for the full-range fractal image
      double maxY = 2.0; // use 2 for the full-range fractal image
  
      double xStepSize = ( maxX - minX ) / width;
      double yStepSize = ( maxY - minY ) / height;
      int maxIterations = 100;
      int maxColors = 0xFF0000;
  
      // for each pixel on the screen
      for( x = minX; x &lt; maxX; x = x + xStepSize)
      {
          for ( y = minY; y &lt; maxY; y = y + yStepSize )
          {
              C = new Complex( x, y );
              Z = new Complex( 0, 0 );
              int iter = getIterValue( Z, C, 0, maxIterations );
  
              int myX = (int) ( ( x - minX ) / xStepSize );
              int myY = (int) ( ( y - minY ) / yStepSize );
              if ( iter &lt; maxIterations )
              {
                  myPixel[ myY * width + myX ] = iter * ( maxColors / maxIterations ) / 50; 
              }
          }
      }
  }
  </code></pre>
  
  <p>According to smooth color pseudo-code, it calls for this:</p>
  
  <p><code>nsmooth := n + 1 - Math.log(Math.log(zn.abs()))/Math.log(2)</code></p>
  
  <p>With that said, from my method, the best I have is a bit-fiddled RGB from this line:</p>
  
  <pre><code>if ( iter &lt; maxIterations )
  {
      myPixel[ myY * width + myX ] = iter * ( maxColors / maxIterations ) / 50; 
  }
  </code></pre>
  
  <p>So I am at loss as to what to do. Any help would be very appreciated.</p>
  
  <p>Attached is also the method to get my iteration value:</p>
  
  <pre><code>public static int getIterValue( Complex Z, Complex C, int iter, int maxNumIters )
      {
          if ( Z.getMag() &lt; 2 &amp;&amp; iter &lt; maxNumIters )
          {
              Z = ( Z.multiplyNum( Z )).addNum( C );
              iter++;
              return getIterValue( Z, C, iter, maxNumIters );
          }
          else
          {
              return iter;
          }
      }
  </code></pre>
  
  <p>As you can tell there's a class to return Complex numbers but that should be self explanatory in itself.</p>