Package toxi.color
Class ColorList
java.lang.Object
toxi.color.ColorList
A container class of concrete colors. ColorLists can be built manually and
are also created when working with
ColorRange
s. The class has various
methods to manipulate all colors in the list in parallel, as well as sort
them by various criteria.- See Also:
-
Constructor Summary
ConstructorDescriptionCreates an empty list.ColorList
(int[] argbArray) Creates a new color list from the array of ARGB int values.ColorList
(Collection<TColor> colors) Creates a ColorList by wrapping the given ArrayList of colors.Creates a deep copy of the given ColorList.ColorList
(ReadonlyTColor... colorArray) Creates new ColorList from the given colors. -
Method Summary
Modifier and TypeMethodDescriptionAdds a copy of the given color to the listaddAll
(Collection<TColor> collection) Adds all entries of the TColor collection to the list (shallow copy only, manipulating the new list will modify the original colors).adjustBrightness
(float step) Adjusts the brightness component of all list colors by the given amount.adjustSaturation
(float step) Adjusts the saturation component of all list colors by the given amount.clusterSort
(AccessCriteria clusterCriteria, AccessCriteria subClusterCriteria, int numClusters, boolean isReversed) Sorts the list based on two criteria to create clusters/segments within the list.Switches all list colors to their complementary color.boolean
contains
(ReadonlyTColor color) Checks if the given color is part of the list.static final ColorList
createFromARGBArray
(int[] pixels, int num, boolean uniqueOnly) Factory method.static final ColorList
createFromARGBArray
(int[] pixels, int num, boolean uniqueOnly, int maxIterations) Factory method.static final ColorList
createUsingStrategy
(String name, TColor c) Factory method.static final ColorList
createUsingStrategy
(ColorTheoryStrategy strategy, TColor c) Factory method.get
(int i) Returns the color at the given index.Calculates and returns the average color of the list.getBlended
(float amount) Creates a new ColorList by blending all colors in the list with each other (successive indices only)Finds and returns the darkest color of the list.Finds and returns the lightest (luminance) color of the list.Returns a reversed copy of the current list.invert()
Inverts all colors in the list.iterator()
Returns an iterator over the internal list.reverse()
Reverses the current order of the list.rotateRYB
(float theta) Rotates the hues of all colors in the list by the given amount.rotateRYB
(int angle) Rotates the hues of all colors in the list by the given amount.int
size()
sort()
Convenience method.sortByComparator
(Comparator<ReadonlyTColor> comp, boolean isReversed) Sorts the list using the given comparator.sortByCriteria
(AccessCriteria criteria, boolean isReversed) Sorts the list using the givenAccessCriteria
.sortByDistance
(boolean isReversed) Sorts the list by relative distance to each predecessor, starting with the darkest color in the list.sortByDistance
(DistanceProxy proxy, boolean isReversed) Sorts the list by relative distance to each predecessor, starting with the darkest color in the list.sortByProximityTo
(ReadonlyTColor target, boolean isReversed) Sorts the list by proximity to the given target color (using RGB distance metrics).sortByProximityTo
(ReadonlyTColor target, DistanceProxy proxy, boolean isReversed) Sorts the list by proximity to the given target color using the givenDistanceProxy
implementation.int[]
Creates an ARGB integer array of the list items.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ColorList
public ColorList()Creates an empty list. -
ColorList
Creates a ColorList by wrapping the given ArrayList of colors. No copies of the given colors are created (shallow copy only).- Parameters:
colors
-
-
ColorList
Creates a deep copy of the given ColorList. Manipulating the new list or its color entries does NOT change the colors of the original.- Parameters:
list
- source list to copy
-
ColorList
public ColorList(int[] argbArray) Creates a new color list from the array of ARGB int values. In most cases this will be the pixel buffer of an image.- Parameters:
argbArray
-
-
ColorList
Creates new ColorList from the given colors. Copies of the given colors are created. This is a varargs constructor allowing these two parameter formats:// individual parameters ColorList cols=new ColorList(TColor.BLACK,TColor.WHITE,TColor.newRGB(1,0,0)); // or array of colors ReadonlyTColor[] colArray=new ReadonlyTColor[] { TColor.BLACK,TColor.WHITE,TColor.newRGB(1,0,0); }; ColorList cols=new ColorList(colArray);
- Parameters:
colorArray
-
-
-
Method Details
-
createFromARGBArray
Factory method. Creates a new ColorList of colors sampled from the given ARGB image array. If the number of samples equals or exceeds the number of pixels in the image and no unique colors are required, the function will simply return the same asColorList(int[])
.- Parameters:
pixels
- int array of ARGB pixelsnum
- number of colors samples (clipped automatically to number of pixels in the image)uniqueOnly
- flag if only unique samples are to be taken (doesn't guarantee unique colors though)- Returns:
- new color list
-
createFromARGBArray
public static final ColorList createFromARGBArray(int[] pixels, int num, boolean uniqueOnly, int maxIterations) Factory method. Creates a new ColorList of colors randomly sampled from the given ARGB image array. If the number of samples equals or exceeds the number of pixels in the source image and no unique colors are required, the function will simply return the same asColorList(int[])
.- Parameters:
pixels
- int array of ARGB pixelsnum
- number of colors samples (clipped automatically to number of pixels in the image)uniqueOnly
- flag if only unique samples are to be taken (doesn't guarantee unique colors though)maxIterations
- max number of attempts to find a unique color. If no more unique colors can be found the search is terminated.- Returns:
- new color list of samples
-
createUsingStrategy
Factory method. Creates a new ColorList based on the givenColorTheoryStrategy
instance and the given source color. The number of colors returned will vary with the strategy chosen.- Parameters:
strategy
-c
-- Returns:
- new list
-
createUsingStrategy
Factory method. Creates a ColorList based on the name of aColorTheoryStrategy
and the given source color.- Parameters:
name
- strategy namec
-- Returns:
- new color list or null, if the supplied strategy name is not mapped to a registered implementation.
-
add
Adds a copy of the given color to the list- Parameters:
c
-- Returns:
- itself
-
addAll
Adds all entries of the TColor collection to the list (shallow copy only, manipulating the new list will modify the original colors).- Parameters:
collection
-- Returns:
- itself
-
adjustBrightness
Adjusts the brightness component of all list colors by the given amount.- Parameters:
step
- adjustment value- Returns:
- itself
-
adjustSaturation
Adjusts the saturation component of all list colors by the given amount.- Parameters:
step
- adjustment value- Returns:
- itself
-
clusterSort
public ColorList clusterSort(AccessCriteria clusterCriteria, AccessCriteria subClusterCriteria, int numClusters, boolean isReversed) Sorts the list based on two criteria to create clusters/segments within the list.- Parameters:
clusterCriteria
- main sort criteriasubClusterCriteria
- secondary sort criterianumClusters
- number of clustersisReversed
- true, if reversed sort- Returns:
- itself
-
complement
Switches all list colors to their complementary color.- Returns:
- itself
-
contains
Checks if the given color is part of the list. Check is done by value, not instance.- Parameters:
color
-- Returns:
- true, if the color is present.
-
get
Returns the color at the given index. This function follows Python convention, in that if the index is negative, it is considered relative to the list end. Therefore the color at index -1 is the last color in the list.- Parameters:
i
- index- Returns:
- color
-
getAverage
Calculates and returns the average color of the list.- Returns:
- average color or null, if there're no entries yet.
-
getBlended
Creates a new ColorList by blending all colors in the list with each other (successive indices only)- Parameters:
amount
- blend amount- Returns:
- new color list
-
getDarkest
Finds and returns the darkest color of the list.- Returns:
- darkest color or null if there're no entries yet.
-
getLightest
Finds and returns the lightest (luminance) color of the list.- Returns:
- lightest color or null, if there're no entries yet.
-
getRandom
-
getReverse
Returns a reversed copy of the current list.- Returns:
- reversed copy of the list
-
invert
Inverts all colors in the list.- Returns:
- itself
-
iterator
Returns an iterator over the internal list. This means the list can be accessed via standard Iterator loops. -
reverse
Reverses the current order of the list.- Returns:
- itself
-
rotateRYB
Rotates the hues of all colors in the list by the given amount.- Parameters:
theta
- rotation angle in radians- Returns:
- itself
-
rotateRYB
Rotates the hues of all colors in the list by the given amount.- Parameters:
angle
- rotation angle in degrees- Returns:
- itself
-
size
public int size()- Returns:
- the number of colors in the list
-
sort
Convenience method. Sorts the list by hue.- Returns:
- itself
-
sortByComparator
Sorts the list using the given comparator.- Parameters:
comp
- comparatorisReversed
- true, if reversed sort- Returns:
- itself
-
sortByCriteria
Sorts the list using the givenAccessCriteria
.- Parameters:
criteria
- sort criteriaisReversed
- true, if reversed sort- Returns:
- itself
-
sortByDistance
Sorts the list by relative distance to each predecessor, starting with the darkest color in the list.- Parameters:
isReversed
- true, if list is to be sorted in reverse.- Returns:
- itself
-
sortByDistance
Sorts the list by relative distance to each predecessor, starting with the darkest color in the list.- Parameters:
isReversed
- true, if list is to be sorted in reverse.- Returns:
- itself
-
sortByProximityTo
Sorts the list by proximity to the given target color (using RGB distance metrics).- Parameters:
target
- colorisReversed
- true, if reverse sorted- Returns:
- sorted list
- See Also:
-
sortByProximityTo
Sorts the list by proximity to the given target color using the givenDistanceProxy
implementation.- Parameters:
target
- colorproxy
- distance metricsisReversed
- true, if reverse sorted- Returns:
- sorted list
-
toARGBArray
public int[] toARGBArray()Creates an ARGB integer array of the list items.- Returns:
- all list colors as ARGB values
-