public class ColorPalette
extends java.lang.Object
| Constructor and Description |
|---|
ColorPalette()
Builds an empty color palette.
|
ColorPalette(java.util.ArrayList<RColor> colors)
Creates a color palette with the given colors.
|
ColorPalette(int[] colors)
Creates a color palette with the given colors.
|
ColorPalette(RColor[] colors)
Creates a color palette with the given colors.
|
ColorPalette(java.lang.String jsonString)
Builds an ColorPalette out of a JSON-styled String.
|
| Modifier and Type | Method and Description |
|---|---|
ColorPalette |
add(int c)
Adds a color to this palette.
|
ColorPalette |
add(int c,
int importance)
Adds a color to this palette.
|
ColorPalette |
add(RColor c)
Adds a color to this palette.
|
ColorPalette |
add(RColor c,
int importance)
Adds a color to this palette.
|
ColorPalette |
addTag(java.lang.String tag)
Adds a tag (e.g.
|
ColorPalette |
addTags(java.lang.String... tags)
Adds one or more tags (e.g.
|
ColorPalette |
applyImportance(int[] importances)
Sets the importances of the palettes colors.
|
ColorPalette |
applyImportance(int c,
int importance)
Sets the importance of a color.
|
ColorPalette |
applyImportance(RColor c,
int importance)
Sets the importance of a color.
|
ColorPalette |
copy()
Creates a true copy of this palette.
|
ColorPalette |
draw(processing.core.PApplet parent,
float x,
float y,
float w,
float h)
Draws a simple representation of this color palette within a rectangular
form.
|
RColor |
find(float tplusi)
Finds a lerped color within the color palette.
|
boolean |
finishedImage(java.lang.String timestamp)
Returns whether a quantization of an image is finished.
|
RColor |
get(int index)
Returns the color at the given index or null if the index is out of
bounds.
|
java.lang.String |
get(processing.core.PImage img)
Replaces all colors of all pixels of the input image with a color of the
palette.
|
RColor |
get(RColor c)
Returns a color of the palette which is similar to the input color.
|
ColorDifferenceMeasure |
getColorDifferenceMeasure()
Returns the current ColorDifferenceMeasure.
|
RColor[] |
getColors()
Returns all colors of this palette (Shallow copies).
|
ColorSpace |
getColorSpace()
Returns the current ColorSpace.
|
java.lang.String |
getDithered(processing.core.PImage img,
float dithering)
Replaces all colors of all pixels of the input image with a color of the
palette.
|
RColor |
getDithered(RColor c,
float dithering)
Returns a color of the palette which is similar to the input color (but
maybe not the most similar color).
|
int |
getIndex(RColor c)
Returns the index of the most similar color to the input color.
|
java.lang.Float |
getMaxChroma()
Returns the maximal chroma (perceived saturation) of the palette.
|
java.lang.Float |
getMaxLuminance()
Returns the maximal luminance (perceived brightness) of the palette.
|
java.lang.Float |
getMinChroma()
Returns the minimal chroma (perceived saturation) of the palette.
|
java.lang.Float |
getMinLuminance()
Returns the minimal luminance (perceived brightness) of the palette.
|
RColor |
getMostImportantColor()
Returns the most important color of this palette.
|
java.lang.String |
getName()
Returns the currently set name of this palette.
|
java.lang.String |
getNoisy(processing.core.PImage img,
float amt)
Replaces all colors of all pixels of the input image with a color of the
palette.
|
RColor |
getNoisy(RColor c,
float amt)
Returns a color of the palette which is similar to the input color.
|
RColor |
getRandom()
Returns a random color of the color palette.
|
RColor |
getRandomWeighted()
Returns a random color of the color palette by the color's importance.
|
java.util.ArrayList<java.lang.String> |
getTags()
Returns all tags associated with this palette.
|
float |
getWeighting(RColor c)
Calculates the weighting of a color.
|
ColorPalette |
increaseImportance(RColor c,
int howMuch)
Increases the importance of the given color.
|
ColorPalette |
merge(ColorPalette other)
Merges two color palettes - adds another color palette to this one.
|
ColorPalette |
reduceSize(int size)
Reduces the number of colors to the given size.
|
ColorPalette |
remove(int c)
Removes the given color from the palette.
|
ColorPalette |
remove(RColor c)
Removes the given color from the palette.
|
ColorPalette |
removeName()
Removes the currently set name for this palette.
|
ColorPalette |
removeTag(java.lang.String tag)
Removes the given tag from the tag list associated with this palette.
|
ColorPalette |
resetImportance()
Resets the importance of all member colors of the palette to 1 (all
colors are weighted equally).
|
ColorPalette |
save(processing.core.PApplet parent)
This method saves a JSON file containing this palettes color information.
|
ColorPalette |
save(processing.core.PApplet parent,
java.lang.String folder)
This method saves a JSON file containing this palettes color information.
|
ColorPalette |
save(processing.core.PApplet parent,
java.lang.String folder,
java.lang.String name)
This method saves a JSON file containing this palettes color information.
|
ColorPalette |
save(java.lang.String path)
This method saves a JSON file containing this palettes color information.
|
ColorPalette |
save(java.lang.String path,
java.lang.String name)
This method saves a JSON file containing this palettes color information.
|
ColorPalette |
setColorDifferenceMeasure(ColorDifferenceMeasure m)
Sets the ColorDifferenceMeasure.
|
ColorPalette |
setColorSpace(ColorSpace space)
Sets the measure which will be used to calculate the most similar color
from an input to one of the palette's color.
|
ColorPalette |
setColorSpace(RColor c)
Sets the measure which will be used to calculate the most similar color
from an input to one of the palette's color.
|
ColorPalette |
setName(java.lang.String name)
Sets a name which will be associated with this palette.
|
int |
size()
Returns the number of colors in this palette.
|
ColorPalette |
sort()
Sorts the colors by luminance beginning with the lowest luminance.
|
ColorPalette |
sort(java.lang.String how)
Sorts the colors by a parameter beginning with the lowest.
|
int[] |
toColors()
Returns all colors of this palette.
|
java.lang.String |
toString() |
public ColorPalette()
public ColorPalette(java.lang.String jsonString)
{
"name" : "String",
"tags" : ["String1","String2",...,"StringN"],
"colors" : [
{
"hexString" : {
"r" : "float",
"g" : "float",
"b" : "float"}
"a" : "float",
"importance" : "int"
}
}, ...]
}
jsonString - The String containing JSON color infos.public ColorPalette(RColor[] colors)
colors - The colors of the palette.public ColorPalette(java.util.ArrayList<RColor> colors)
colors - The colors of the palette.public ColorPalette(int[] colors)
colors - The colors of the palette.public java.lang.Float getMaxLuminance()
public java.lang.Float getMinLuminance()
public java.lang.Float getMaxChroma()
public java.lang.Float getMinChroma()
public RColor getMostImportantColor()
public ColorDifferenceMeasure getColorDifferenceMeasure()
public ColorSpace getColorSpace()
public ColorPalette setColorSpace(ColorSpace space)
space - The new color space of this palette.public ColorPalette setColorSpace(RColor c)
c - One color.public ColorPalette setColorDifferenceMeasure(ColorDifferenceMeasure m)
m - A ColorDifferenceMeasure. e.g.
ColorDifferenceMeasure.RGBEuclidean.public float getWeighting(RColor c)
c - The color of which the weighing should be returned.public ColorPalette addTag(java.lang.String tag)
tag - The tag.public ColorPalette addTags(java.lang.String... tags)
tags - The tags.public ColorPalette removeTag(java.lang.String tag)
tag - The tag to be removed.public java.util.ArrayList<java.lang.String> getTags()
public ColorPalette setName(java.lang.String name)
name - The new name of this palette.public ColorPalette removeName()
public java.lang.String getName()
public ColorPalette add(int c)
c - The color which will be added to the palette.public ColorPalette add(int c, int importance)
c - The color which will be added to the palette.importance - The importance value > 1 of this color.public ColorPalette add(RColor c)
c - - The color which will be added to the palette.public ColorPalette add(RColor c, int importance)
c - The color which will be added to the palette.importance - The importance value > 1 of this color.public ColorPalette resetImportance()
public ColorPalette increaseImportance(RColor c, int howMuch)
c - The color of which the importance should be increased.howMuch - A positive number which will be added to the current
importance.public ColorPalette applyImportance(RColor c, int importance)
c - - The color of which the importance should be set.importance - - The importance value > 0 for the input color.public ColorPalette applyImportance(int c, int importance)
c - The color of which the importance should be set.importance - The importance value > 0 for the input color.public ColorPalette applyImportance(int[] importances)
importances - - The importance values > 0 for all colors of the palette.public ColorPalette remove(RColor c)
c - The color which should be removed.public ColorPalette remove(int c)
c - The color which should be removed.public ColorPalette merge(ColorPalette other)
other - Any other color palette. Duplicate colors are allowed. "other"
will not be changed by this method.public ColorPalette sort()
public ColorPalette sort(java.lang.String how)
how - Defines how the palette is sorted. Possible parameters are:
"luminance", "chroma", "hue" (hue in HSB), "huelch (hue in
CieLCH), "brightness", "saturation", "red", "green", "blue",
"weighting".public ColorPalette copy()
public ColorPalette reduceSize(int size)
size - The new number of colors for this palette (size > 1 and size <
palette.size()).public int size()
public RColor getRandom()
public RColor getRandomWeighted()
public RColor getDithered(RColor c, float dithering)
c - The input color.dithering - The value for the dithering (0, 1).public java.lang.String getDithered(processing.core.PImage img,
float dithering)
String stamp = myPalette.getDithered(myImage, 0.25); ⁄⁄ return true when all pixels of the input image have been ⁄⁄ replaced boolean finished = myPalette.finishedImage(stamp);
img - The input image.dithering - The value for the dithering (0, 1).public RColor getNoisy(RColor c, float amt)
c - The input color.amt - The value for the noise (>= 0).public java.lang.String getNoisy(processing.core.PImage img,
float amt)
String stamp = myPalette.getNoisy(myImage, 0.25); ⁄⁄ return true when all pixels of the input image have been ⁄⁄ replaced boolean finished = myPalette.finishedImage(stamp);
img - The input image.amt - The value for the noise (>= 0).public RColor get(RColor c)
c - The input color.public java.lang.String get(processing.core.PImage img)
String stamp = myPalette.get(myImage); ⁄⁄ return true when all pixels of the input image have been ⁄⁄ replaced boolean finished = myPalette.finishedImage(stamp);
img - The input image.public RColor get(int index)
index - The index of the color which should be returned.public RColor find(float tplusi)
tplusi - The parameter describes the returned color's position within
the palette. It is calculated with t + i, where t is a float
in range of [0, 1) and i is an int in range of [0, size() -
1). For example, if the color in the middle of the first and
second color of the palette should be returned, than i=1 and
t=0.5 and therefor tplusi=1.5.public int getIndex(RColor c)
c - The input color.public boolean finishedImage(java.lang.String timestamp)
timestamp - The timestamp of the start of quantization.public ColorPalette save(processing.core.PApplet parent)
myPalette.save(this);
parent - A PApplet object.public ColorPalette save(processing.core.PApplet parent, java.lang.String folder)
folder - The name of the folder, where the palette should be saved. Can
also be a relative path to the folder. Make sure to escape the
backslashes when providing a relative path. Example usage in
Processing:
// will save the file in the current sketch folder in a sub-folder named
// "colors"
myPalette.save(this, "colors");
// will save the file in the folder "temp" which will be above the
// current sketch folder
myPalette.save(this, "..\\temp");
parent - A PApplet object.public ColorPalette save(processing.core.PApplet parent, java.lang.String folder, java.lang.String name)
folder - The name of the folder, where the palette should be saved. Can
also be a relative path to the folder. Make sure to escape the
backslashes when providing a relative path. Example usage in
Processing:
// will save the file in the current sketch folder in a sub-folder named
// "colors"
myPalette.save(this, "colors");
// will save the file in the folder "temp" which will be above the
// current sketch folder
myPalette.save(this, "..\\temp");
name - The name of the file (without file extension) under which the
palette should be saved. Make sure this is a valid file name.
Read Wiki: Filename for further informations.parent - A PApplet object.public ColorPalette save(java.lang.String path)
path - An absolute path to the place where the palette should be
saved. Make sure this path exists! Otherwise (e.g. if you want
to provide a relative path) please use the save(PApplet)
method.public ColorPalette save(java.lang.String path, java.lang.String name)
path - An absolute path to the place where the palette should be
saved. Make sure this path exists! Otherwise (e.g. if you want
to provide a relative path) please use the save(PApplet)
method.name - The name of the file (without file extension) under which the
palette should be saved. Make sure this is a valid file name.
Read Wiki: Filename for further informations.public ColorPalette draw(processing.core.PApplet parent, float x, float y, float w, float h)
parent - A PApplet object (Canvas to draw to).x - The x-value of the rectangle (left).y - The y-value of the rectangle (top).w - The with of the rectangle.h - The height of the rectangle.public int[] toColors()
color[] theColors = myColorPalette.toColors();
public RColor[] getColors()
RColor[] theColors = myColorPalette.getColors();
public java.lang.String toString()
toString in class java.lang.Object