How to improve buddhabrot color?

  • 1 Replies
  • 69 Views

0 Members and 1 Guest are viewing this topic.

Offline Naografix

  • *
  • Fractal Freshman
  • *
  • Posts: 1
« on: January 11, 2019, 10:22:32 AM »
Hey!

I'm new in fractal and currently, I'm trying to generate buddhabrot in color.
I got a good version of my buddha, but I find colors are a little bland:

How can I improve my colors? (I'm trying to get this render: https://urlz.fr/8Cqk )
I'm working with https://processing.org/ and this is my code:
Thank you for your help.


Code: [Select]
int resolution = 1024;
int[][] pixelArray = new int[resolution*resolution][3];

float realMin = -1.6;
float realMax = 0.8;
float imaginaryMin = -1.2;
float imaginaryMax = 1.2;
float escapeOrbit = 4;
PVector minColor = new PVector(200, 50, 1);
PVector maxColor = new PVector(5000, 500, 100);
                         //red        green         blue
int minIter = round(min(minColor.x, minColor.y, minColor.z));
int maxIter = round(max(maxColor.x, maxColor.y, maxColor.z));

boolean process = true;
int iterations = 1600000;

int maxfound = 0;
int maxfoundR = 0;
int maxfoundG = 0;
int maxfoundB = 0;

float luminosity = 1.2;

void setup() {
  size(1024, 1024);
  background(0);
}

void draw() {
  if (process) {
    for (int i = 0; i < iterations; i++) {
      buddhabrot(realMin, realMax, imaginaryMin, imaginaryMax, minIter, maxIter, escapeOrbit, minColor, maxColor);

      if (i >= iterations - 1) {
        process = false;
      }
    }
  } else {
    drawBuddha();
  }
}

void drawBuddha() {

  loadPixels();

  maxfound = max(maxfoundR, maxfoundG, maxfoundB);

  float maxSqrtR = sqrt(maxfoundR);
  float maxSqrtG = sqrt(maxfoundG);
  float maxSqrtB = sqrt(maxfoundB);

  for (int i = 0; i < width * height; i++)
  {
    int colorR = round( min(  (sqrt(pixelArray[i][0]) / maxSqrtR * 255.0) * luminosity, 255));
    int colorG = round( min(  (sqrt(pixelArray[i][1]) / maxSqrtG * 255.0) * luminosity, 255));
    int colorB = round( min(  (sqrt(pixelArray[i][2]) / maxSqrtB * 255.0) * luminosity, 255));

    pixels[i] = color(colorR, colorG, colorB);
  }

  updatePixels();
  process = true;
}

boolean isInMandlebrot(float cr, float ci, int maxIter, float escapeOrbit) {
  int iter = 0;
  float zr = 0.0;
  float zi = 0.0;
  float ci2 = ci*ci;
  float temp;

  //Quick rejection check if c is in 2nd order period bulb
  if ( (cr+1.0) * (cr+1.0) + ci2 < 0.0625) return true;

  //Quick rejection check if c is in main cardioid
  float q = (cr-0.25)*(cr-0.25) + ci2;
  if ( q*(q+(cr-0.25)) < 0.25*ci2) return true;


  // test for the smaller bulb left of the period-2 bulb
  if (( ((cr+1.309)*(cr+1.309)) + ci*ci) < 0.00345) return true;

  // check for the smaller bulbs on top and bottom of the cardioid
  if ((((cr+0.125)*(cr+0.125)) + (ci-0.744)*(ci-0.744)) < 0.0088) return true;
  if ((((cr+0.125)*(cr+0.125)) + (ci+0.744)*(ci+0.744)) < 0.0088) return true;

  while ( (iter < maxIter) && ((zr*zr+zi*zi) < escapeOrbit) )
  {
    temp = zr * zi;
    zr = zr*zr - zi*zi + cr;
    zi = temp + temp + ci;
    iter++;
  }

  if ( iter < maxIter)
  {
    return false;
  } else {
    return true;
  }
}


void buddhabrot(float realMin, float realMax, float imaginaryMin, float imaginaryMax, int minIter, int maxIter, float escapeOrbit, PVector minColor, PVector maxColor)
{
  float x0 = random( -2, 2 );
  float y0 = random( -2, 2 );

  float deltaReal = (realMax - realMin);
  float deltaImaginary = (imaginaryMax - imaginaryMin);

  float cr = realMin + (realMax - realMin) * x0;
  float ci = imaginaryMin + (imaginaryMax - imaginaryMin) * y0;

  int x, y;
  int iter   = 0;
  float zr   = 0.0;
  float zi   = 0.0;
  float temp = 0.0;


  if ( isInMandlebrot(cr, ci, maxIter, escapeOrbit) == false)
  {   
    while ( (iter < maxIter) && ((zr*zr+zi*zi) < escapeOrbit) )
    {
      temp = zr * zi;
      zr = zr*zr - zi*zi + cr;
      zi = temp + temp + ci;

      x = round(((width) * (zr - realMin) / deltaReal));
      y = round(((height) * (zi - imaginaryMin) / deltaImaginary));

      if ( (iter > minIter) && (x>0) && (y>0) && (x<width) && (y<height) )
      {
        if ( (iter > minColor.x) && (iter < maxColor.x) ) {
          pixelArray[x + (y * width)][0]++;

          //Max red
          if (pixelArray[x + (y * width)][0] > maxfoundR) {
            maxfoundR = round(pixelArray[x + (y * width)][0]);
          }
        }
        if ( (iter > minColor.y) && (iter < maxColor.y) ) {
          pixelArray[x + (y * width)][1]++;

          //Max green
          if (pixelArray[x + (y * width)][1] > maxfoundG) {
            maxfoundG = round(pixelArray[x + (y * width)][1]);
          }
        }
        if ( (iter > minColor.z) && (iter < maxColor.z) ) {
          pixelArray[x + (y * width)][2]++;

          //Max blue
          if (pixelArray[x + (y * width)][2] > maxfoundB) {
            maxfoundB = round(pixelArray[x + (y * width)][2]);
          }
        }
      }
      iter++;
    }
  }
}

Offline Softology

  • *
  • Fractal Fanatic
  • ***
  • Posts: 33
« Reply #1 on: January 13, 2019, 09:04:28 PM »
Try tweaking brightness and contrast after you get your final RGB color values.

A quick edit of brightness and contrast of your image in GIMP got this result much closer to your desired outcome.
https://ibb.co/VD6RMwx


xx
Buddhabrot Mag(nifier) - A realtime buddhabrot zoomer

Started by Sharkigator on Other

15 Replies
1169 Views
Last post December 23, 2017, 08:00:35 PM
by Fraktalist
xx
Buddhabrot

Started by Bill Snowzell on Fractal Image Gallery

0 Replies
175 Views
Last post October 12, 2017, 09:53:06 PM
by Bill Snowzell
xx
Buddhabrot

Started by FractalStefan on Image Threads

3 Replies
316 Views
Last post February 26, 2018, 11:28:21 PM
by FractalStefan
xx
Buddhabrot Angel

Started by Sharkigator on Fractal Image Gallery

3 Replies
143 Views
Last post August 30, 2018, 05:56:00 PM
by tavis
xx
Buddhabrot sprout

Started by F. Bernkastel on Fractal Image Gallery

0 Replies
224 Views
Last post November 23, 2017, 07:00:48 PM
by F. Bernkastel