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.

Increase R G B from 0 to 255 gradually .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.