bcds.tools
Class ColorSetGenerator

java.lang.Object
  extended by bcds.tools.ColorSetGenerator

public class ColorSetGenerator
extends java.lang.Object

Generates a set of colors where the colors are (more or less) visually distinguishable. Therefore, the problem of having a set of harmonious colors is not addressed by this class. The core of the implementation (color generation) is based on http://www.krazydad.com/makecolors.php but complementary features were added by me, inspired by "here and there".

Note that the number of colors generated is rather small. For N=5000 (request: 5000 colors)
  MinLightness = 0.09
  MinDistance = 0.05
the result is a set of 100 colors.


Constructor Summary
ColorSetGenerator()
          Default constructor.
 
Method Summary
 void discardSimilars()
          Discards similar colors by calling discardSimilars(0.05f).
 void discardSimilars(float min_dist)
          Compares every pair of colors and discards those any and all that are very "close" to some other color.
 java.util.Set<bcds.tools.ColorSetGenerator.RGB> getColors()
          Returns the list of colors generated by selectColors(int).
 java.lang.String[] getColorsAsStrings(java.lang.String prefix)
          Returns the list of generated colors, where each color is represented by an hex string with the given prefix, typically "#".
 void getFrequencies(float[] freq)
          Returns an array with the current red, green and blue frequencies, in that order.
 void selectColors(int n)
          Selects at most n different colors.
 void setFrequencies(float red_freq, float green_freq, float blue_freq)
          Sets the red, green and blue frequencies.
 void setMinLightness(float min_lightness)
          Provides a way to avoid selecting very "dark" colors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorSetGenerator

public ColorSetGenerator()
Default constructor. Calls setFrequencies(1.66666f, 2.66666f, 3.66666f). The minimum lightness is set to 0.09

Method Detail

getColors

public java.util.Set<bcds.tools.ColorSetGenerator.RGB> getColors()
Returns the list of colors generated by selectColors(int).


getColorsAsStrings

public java.lang.String[] getColorsAsStrings(java.lang.String prefix)
Returns the list of generated colors, where each color is represented by an hex string with the given prefix, typically "#".


setFrequencies

public void setFrequencies(float red_freq,
                           float green_freq,
                           float blue_freq)
Sets the red, green and blue frequencies.


getFrequencies

public void getFrequencies(float[] freq)
Returns an array with the current red, green and blue frequencies, in that order.


setMinLightness

public void setMinLightness(float min_lightness)
Provides a way to avoid selecting very "dark" colors. For example, min_lightness = 0.09 produces a set of quite "light" colors.


selectColors

public void selectColors(int n)
Selects at most n different colors. This code is based on http://www.krazydad.com/makecolors.php Note that fewer than n colors might be returned, especially if n > 700. Use getColors() to retrive the result.


discardSimilars

public void discardSimilars()
Discards similar colors by calling discardSimilars(0.05f). By experimentation, 0.05 seems to be a good "minimum distance".


discardSimilars

public void discardSimilars(float min_dist)
Compares every pair of colors and discards those any and all that are very "close" to some other color. The output is very sensitive to the value of min_dist. With min_dist=0.2 for example, just 6 colors remain. Beware: This algorithm is quadratic in the number of colors (it works on the colors produced by selectColors(int)). It may take a long time.