Package toxi.color
Class ColorRange
java.lang.Object
toxi.color.ColorRange
A ColorRange is a set of contraints to specify possible ranges for hue,
saturation, brightness and alpha independently and use these as creation
rules for new
TColor
s or ColorList
s. The class comes with 11
preset ranges reflecting common demands and color characters. You can also
construct new ranges and manually add additional constraints. Unless the
constraints in a range are very narrow the class will always create random
variations within the constraints. Please see the examples for further
details.
ColorRange
s are a key ingredient for defining ColorTheme
s but
can also be used individually.-
Field Summary
Modifier and TypeFieldDescriptionstatic final ColorRange
Shade definition: saturation 80-100%, brightness: 80-100%static final ColorRange
Shade definition: saturation 5-20%, brightness: 90-100%static final ColorRange
Shade definition: saturation 70-100%, brightness: 15-40%static final float
Default hue variance forgetColor(ReadonlyTColor, float)
static final ColorRange
Shade definition: saturation 40-80%, brightness: 80-100%static final ColorRange
Shade definition: saturation 90-100%, brightness: 40-100%static final ColorRange
Shade definition: saturation 90-100%, brightness: 20-35% or 80-100%static final ColorRange
Shade definition: saturation 30-70%, brightness: 90-100%static final ColorRange
Shade definition: saturation 25-35%, brightness: 30-70%static final HashMap<String,
ColorRange> List of ColorRange presets.static final ColorRange
Shade definition: saturation 20-30%, brightness: 60-90%static final ColorRange
Shade definition: saturation 60-90%, brightness: 40-90%static final ColorRange
Shade definition: saturation 15-30%, brightness: 70-100% -
Constructor Summary
ConstructorDescriptionColorRange
(ColorList list) Constructs a new range using the given colors as HSV constraints.ColorRange
(Hue hue) Constructs a new range using the given hue as constraint, but saturation and brightness are fully flexible.Constructs a new range using the hue of the given color as hue constraint, but saturation and brightness are fully flexible.ColorRange
(FloatRange hue, FloatRange sat, FloatRange bri, String name) Constructs a new range with the supplied constraints (if an argument is null, a range of 0.0 ...ColorRange
(FloatRange hue, FloatRange sat, FloatRange bri, FloatRange alpha, String name) Constructs a new range with the supplied constraints (if an argument is null, a range of 0.0 ...ColorRange
(FloatRange hue, FloatRange sat, FloatRange bri, FloatRange alpha, FloatRange black, FloatRange white, String name) Constructs a new range with the supplied constraints (if an HSV argument is null, a range of 0.0 ... -
Method Summary
Modifier and TypeMethodDescriptionadd
(ColorRange range) Adds the contraints of the given range to this range and forms unions for the black and white point ranges.Adds the HSV color components as constraints.addAlphaRange
(float min, float max) Adds the range between min-max as possible alpha values for this range.addAlphaRange
(FloatRange alpha) Adds an additional alpha constraint.addBrightnessRange
(float min, float max) Adds the range between min-max as possible brightness values for this range.Adds an additional brightness constraint.Add the given hue as hue constraint.addHueRange
(float min, float max) Adds the range between min-max as possible hue values for this range.addHueRange
(FloatRange hue) Adds an additional hue constraint.addSaturationRange
(float min, float max) Adds the range between min-max as possible saturation values for this range.Adds an additional saturation constraint.boolean
Checks if all HSVA components of the given color are within the constraints defined for this range.copy()
Creates a shallow copy of the range.copy
(ReadonlyTColor c, float variance) Creates a copy of the range but overrides the hue and alpha constraints taken from the given color (if specified).getColor()
Creates a new color based on the flexible constraints of the range.Creates a new shade of the given hue based on the other constraints of the range.getColor
(ReadonlyTColor c, float variance) Creates a new color based on the constraints defined in the range.getColors
(int num) Creates a newColorList
of colors based on the constraints of this range.getColors
(ReadonlyTColor c, int num, float variance) getGrayscale
(float brightness, float variance) Creates a new shade of gray based on the input brightness and the black and white constraints of the range.getName()
static ColorRange
getPresetForName
(String name) Retrieves one of the predefined ranges by name.getSum
(ColorRange range) Creates a copy of the current range and adds the given one to it.
-
Field Details
-
DEFAULT_VARIANCE
public static final float DEFAULT_VARIANCEDefault hue variance forgetColor(ReadonlyTColor, float)
- See Also:
-
LIGHT
Shade definition: saturation 30-70%, brightness: 90-100% -
DARK
Shade definition: saturation 70-100%, brightness: 15-40% -
BRIGHT
Shade definition: saturation 80-100%, brightness: 80-100% -
WEAK
Shade definition: saturation 15-30%, brightness: 70-100% -
NEUTRAL
Shade definition: saturation 25-35%, brightness: 30-70% -
FRESH
Shade definition: saturation 40-80%, brightness: 80-100% -
SOFT
Shade definition: saturation 20-30%, brightness: 60-90% -
HARD
Shade definition: saturation 90-100%, brightness: 40-100% -
WARM
Shade definition: saturation 60-90%, brightness: 40-90% -
COOL
Shade definition: saturation 5-20%, brightness: 90-100% -
INTENSE
Shade definition: saturation 90-100%, brightness: 20-35% or 80-100% -
PRESETS
List of ColorRange presets.
-
-
Constructor Details
-
ColorRange
Constructs a new range using the given colors as HSV constraints.- Parameters:
list
- list base colors
-
ColorRange
public ColorRange(FloatRange hue, FloatRange sat, FloatRange bri, FloatRange alpha, FloatRange black, FloatRange white, String name) Constructs a new range with the supplied constraints (if an HSV argument is null, a range of 0.0 ... 1.0 is created automatically for that constraint). If alpha is left undefined, it'll be initialized to fully opaque only. You can also specify ranges for possible black and white points which are used if the range is later applied to a grayscale color. The default black point is at 0.0 and white at 1.0.- Parameters:
hue
-sat
-bri
-alpha
-black
-white
-name
-
-
ColorRange
Constructs a new range with the supplied constraints (if an argument is null, a range of 0.0 ... 1.0 is created automatically for that constraint).- Parameters:
hue
- min/max hue rangesat
- min/max saturation rangebri
- min/max brightness rangealpha
- min/max alpha range (if null, initialized to 100% only)name
-
-
ColorRange
Constructs a new range with the supplied constraints (if an argument is null, a range of 0.0 ... 1.0 is created automatically for that constraint). Alpha constraint will be set to 100%.- Parameters:
hue
- min/max hue rangesat
- min/max saturation rangebri
- min/max brightness rangename
-
-
ColorRange
Constructs a new range using the given hue as constraint, but saturation and brightness are fully flexible. The resulting range will produce any shade of the given hue.- Parameters:
hue
- base hue
-
ColorRange
Constructs a new range using the hue of the given color as hue constraint, but saturation and brightness are fully flexible. The resulting range will produce any shade of the given color.- Parameters:
c
- base color
-
-
Method Details
-
getPresetForName
Retrieves one of the predefined ranges by name.- Parameters:
name
-- Returns:
- color range or null if name not registered
-
add
Adds the contraints of the given range to this range and forms unions for the black and white point ranges.- Parameters:
range
- color range to add- Returns:
- itself
-
add
Adds the HSV color components as constraints.- Parameters:
c
- color to use as constraint- Returns:
- itself
-
addAlphaRange
Adds the range between min-max as possible alpha values for this range.- Parameters:
min
-max
-- Returns:
- itself
-
addAlphaRange
Adds an additional alpha constraint.- Parameters:
alpha
- min/max alpha values- Returns:
- itself
-
addBrightnessRange
Adds the range between min-max as possible brightness values for this range.- Parameters:
min
-max
-- Returns:
- itself
-
addBrightnessRange
Adds an additional brightness constraint.- Parameters:
bri
- min/max brightness values- Returns:
- itself
-
addHue
Add the given hue as hue constraint.- Parameters:
hue
-- Returns:
- itself
-
addHueRange
Adds the range between min-max as possible hue values for this range. If max < min then two intervals are added: {min ... 1.0} and {0.0 ... max}- Parameters:
min
-max
-- Returns:
- itself
-
addHueRange
Adds an additional hue constraint.- Parameters:
hue
- min/max hue values- Returns:
- itself
-
addSaturationRange
Adds the range between min-max as possible saturation values for this range.- Parameters:
min
-max
-- Returns:
- itself
-
addSaturationRange
Adds an additional saturation constraint.- Parameters:
sat
- min/max saturation values- Returns:
- itself
-
contains
Checks if all HSVA components of the given color are within the constraints defined for this range.- Parameters:
c
- color to check- Returns:
- true, if color is contained
-
copy
Creates a shallow copy of the range.- Returns:
- copy
-
copy
Creates a copy of the range but overrides the hue and alpha constraints taken from the given color (if specified).- Parameters:
c
- color, if the new range is to be used to create specific shades of that color onlyvariance
- hue variance (useDEFAULT_VARIANCE
for default)- Returns:
- copy
-
getColor
Creates a new color based on the flexible constraints of the range.- Returns:
- color
-
getColor
Creates a new shade of the given hue based on the other constraints of the range.- Parameters:
hue
-- Returns:
- color
-
getColor
Creates a new color based on the constraints defined in the range. If an input color is specified, the method will use the hue of that color and the given variance to create a shade of a hue within the tolerance.- Parameters:
c
-variance
-- Returns:
- color
-
getColors
Creates a newColorList
of colors based on the constraints of this range.- Parameters:
num
- number of colors to create- Returns:
- color list
- See Also:
-
getColors
- Parameters:
c
- base colornum
- number of colors to createvariance
- hue variance- Returns:
- color list
- See Also:
-
getGrayscale
Creates a new shade of gray based on the input brightness and the black and white constraints of the range.- Parameters:
brightness
- input brightnessvariance
- hue variance (this might seem irrevelant, but might be important if the created color is being saturated later on)- Returns:
- color/shade of gray
-
getName
- Returns:
- name of the range
-
getSum
Creates a copy of the current range and adds the given one to it.- Parameters:
range
- range to add- Returns:
- summed copy
- See Also:
-