Jump to my Home Page Send me a message Check out stuff on GitHub Check out my photography on Instagram Check out my profile on LinkedIn Check out my profile on reddit Check me out on Facebook

Mitch Richling: Tricorn Fractal

Author: Mitch Richling
Updated: 2024-10-31

tricorn_01_3.png tricorn_02_3.png tricorn_03_3.png tricorn_04_3.png

Table of Contents

1. Introduction

The Tricorn Fractal is another Mandelbrot'alike in that its generating function is a minor modification of the one used for the Mandelbrot Set:

\[\begin{eqnarray} f(z) & = & z^2+c & \,\,\,\,\,\,\mathrm{Mandelbrot} \\ f(z) & = & \bar{z}^2+c & \,\,\,\,\,\,\mathrm{Tricorn} \\ \end{eqnarray}\]

We render Tricorn Fractals using the \(L\) function just like we did with the Mandelbrot Set. The general idea is to map an array of pixels making up the raster image to a rectangular region of the complex plane, and color each pixel of the image based upon a color scale for the computed value of the \(L\) function.

2. Algorithms

#include "ramCanvas.hpp"

int main(void) {
  std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
  const int    NUMITR = 1024;
  const int    IMXSIZ = 7680/2;
  const int    IMYSIZ = 7680/2;

  mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -2.75, 2.75, -2.75, 2.75);      // The whole thing
  //mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -2.1, -0.30, -0.25, 0.25);      // The "corn"
  //mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -1.65, -1.46, -0.07, 0.07);  // Tiny tricorns & mandelbrots
  //mjr::ramCanvas3c8b theRamCanvas(IMXSIZ, IMYSIZ, -1.48-0.0065, -1.48+0.007, -0.0035, 0.0035); // That biggest mandelbrot-like set from above

  for(int y=0;y<theRamCanvas.getNumPixY();y++) {
    for(int x=0;x<theRamCanvas.getNumPixX();x++) {
      std::complex<double> c(theRamCanvas.int2realX(x), theRamCanvas.int2realY(y));
      std::complex<double> z(0.0, 0.0);
      int count = 0; 
      while((std::norm(z)<14) && (count<=NUMITR)) {
        z=std::pow(std::conj(z), 2) + c;
        count++;
      }
      if(count < NUMITR)
        theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType::csCColdeFireRamp::c(static_cast<mjr::ramCanvas3c8b::csIntType>(count*30)));
    }
  }
  theRamCanvas.writeTIFFfile("tricorn.tiff");
  std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
  std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
}

The above program will generate the following image:

tricorn_01_20.png

4. References

Check out the fractals section of my reading list.

All the code used to generate everything on this page may be found on github.