|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbcds.tools.ColorSetGenerator
public class ColorSetGenerator
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 |
---|
public ColorSetGenerator()
Method Detail |
---|
public java.util.Set<bcds.tools.ColorSetGenerator.RGB> getColors()
selectColors(int)
.
public java.lang.String[] getColorsAsStrings(java.lang.String prefix)
prefix
,
typically "#".
public void setFrequencies(float red_freq, float green_freq, float blue_freq)
public void getFrequencies(float[] freq)
public void setMinLightness(float min_lightness)
public void selectColors(int n)
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.
public void discardSimilars()
public void discardSimilars(float min_dist)
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |