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: Inverted Mandelbrot

Author: Mitch Richling
Updated: 2024-10-31

invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png invertedMandelbrot_2.png

Table of Contents

1. Introduction

This is really just the Mandelbrot Set remapped to the complex plane via the reciprocal function. The \(\frac{1}{z}\) function turns the Mandelbrot Set inside out with the point \(0+0i\) mapping to \(\infty\) – so the Mandelbrot Set proper is the black space extending outside the teardrop and stretching out to infinity.

2. Algorithm & Code

#include "ramCanvas.hpp"

typedef mjr::ramCanvas3c8b::colorType ct;

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, -1.5, 4.25, -2.875, 2.875);

  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));
      if (std::norm(c)>1e-5) {
        std::complex<double> z(0.0, 0.0);
        int count = 0; 
        c = 1.0 / c;
        while((std::norm(z)<50) && (count<=NUMITR)) {
          z=std::pow(z, 2) + c;
          count++;
        }
        if(count < NUMITR)          
          theRamCanvas.drawPoint(x, y, ct::csCColdeFireRamp::c(static_cast<ct::csIntType>(count*15)));
      }
    }
  }
  theRamCanvas.writeTIFFfile("invertedMandelbrot.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 picture:

invertedMandelbrot_20.png

3. 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.