954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Fractal Color Generation

Hello! I'm writing a fractal generation application. I have the fractal part down, but I can't seem to get the coloring right.

What I want to do is, as the number gets closer to infinity, the pixel it relates to's color should get darker (Black relating to infinity, The other color relating to 0).

Currently, I'm doing the following to compute the colors:

minMagnitude = 100.0;
        maxMagnitude = 0.0;

        System.out.println("MAXMAG = "+maxMagnitude+"\nMINMAG = "+minMagnitude);

        // Find the lowest & highest magnitudes
        for(int i=0;i<width;i++){
            for(int j=0;j<height;j++){
                if(doubles[i][j]>maxMagnitude){
                    maxMagnitude = doubles[i][j];
                }

                if(doubles[i][j]<minMagnitude){
                    minMagnitude = doubles[i][j];
                }
            }
        }

        System.out.println("MAXMAG = "+maxMagnitude+"\nMINMAG = "+minMagnitude);

        double value = maxMagnitude-minMagnitude;
        double ratio = 1.0/value;

        // Calculate color values
        for(int i=0;i<width;i++){
            for(int j=0;j<height;j++){
                colors[i][j] = Color.HSBtoRGB((float)(doubles[i][j]*ratio), .3f, .7f);
            }
        }


From the printlns, I know that the number range from almost Zero, to Infinity:

MAXMAG = 0.0
MINMAG = 100.0
MAXMAG = Infinity
MINMAG = 1.4797537555783645E-5


The MAG (Magnitude) variables are calculated like so:
(Where a & b are variables in a Complex Number (a+bi) )

public class ComplexNumber{
    //... Other methods
    public double magnitude(){
        return this.a*this.a+this.b*this.b;
    }


The coloring should be a smooth gradient, but instead it is much more contrasted (Sorry, if that's the wrong word, I'm not an artsy guy...).

If anyone knows of a solution, it would be great if you could point me in the right direction =).

Also, I've included a picture of what is happening when it runs.

Attachments FractalColorMishap.bmp (739.33KB)
llemes4011
Posting Whiz in Training
224 posts since Aug 2008
Reputation Points: 41
Solved Threads: 13
 

Increase R G B from 0 to 255 gradually .

ithelp
Nearly a Posting Maven
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: