0

I have a list of double values that range from 0 to 1 as a result of my mandelbrot generator. These are resultant values from using a smooth algorithm to smooth out the values.

I am in the process of drawing them onto a BufferedImage, however, the BufferedImage calls for the bi.setRGB(), which for my example, looks like this: bi.setRGB(0, 0, width, height, myPixel, 0, width);

As you can tell, the myPixel is an int[] array.

This is my snippet within the Mandelbrot smoothing:

double nsmooth = iter + 1 - Math.log(Math.log(Math.abs(_Z.getMag()))/Math.log(2))/Math.log(2);
myPixel[ myY * width + myX ] = (nsmooth / maxIterations);

The second line above are values ranging from 0.0 to 1.0 (nsmooth / maxIterations), but since myPixel[] is an int array, I need some way to convert them to integer. Multiplying them by a factor of 10000+ did not work.

My question is, with my doubles from 0 to 1.0, what is it that I can do to convert them to a compliable object that setRGB can accept?

Thank you.

Attempt 2:

myPixel[ myY * width + myX ] = (int)(nsmooth / maxIterations * 500);

It appears I was casting nsmooth only which resulted in 0 in every single value. I now casted the entire line, and multiplying it by a factor of 500. It looks a bit better, but maybe my value needs to be bigger:

enter image description here

theGreenCabbage
  • 5,197
  • 19
  • 79
  • 169

1 Answers1

0
double nsmooth = iter + 1 - Math.log(Math.log(Math.abs(_Z.getMag()))/Math.log(2))/Math.log(2);

myPixel[ myY * width + myX ] = (int)(nsmooth / maxIterations * 500);

It appears the issue I had was that I casted nsmooth (a 0 to 1.0 decimal) to int which always resulted in 0.

theGreenCabbage
  • 5,197
  • 19
  • 79
  • 169