public class Hue
extends java.lang.Object
Vona's utils: a color hue, a-la "Color Bytes" by Jean Bourges.
Bourges, Jean. (1997). Color Bytes. Forest Hills, New York: Chromatics Press, Inc.
Jean Bourges is the daughter of Albert R. Bourges (1881-1955), a pioneer in color theory. In "Color Bytes", she documents a practical approach to colors.
The Bourges system first identifies 20 particular "hue"s (see the
*Hue
constants in this class and getHue(int)
) which,
when plotted in the CIE 1976 La*b* color space, form an approximate circle
around the origin. Thus, the hues form a color wheel, and connecting them
in a closed chain imposes a path through color space that is homeomorphic to
a circle. Already this is quite useful, as it enables one-parameter
interpolation across a color spectrum (see getHue(double)
and
interpolateHue(vona.color.Hue, vona.color.Hue, double)
), and it pre-selects 20 "nice" colors and assigns
them intuitive, human-understandable names (see getName()
).
A hue defines a basic color, called herein the "maximum tint", or simply
"the color" of the hue (see getColor()
, but three additional knobs
can be turned on a hue to generate associated colors (see getColor(float, float, float)
):
MIN_TINT
to MAX_TINT
,
which effectively makes the color "softer" or "louder"MIN_BLACK
to MAX_BLACK
, making the color "lighter" or "darker"MIN_ALPHA
to MAX_ALPHA
, making the color more or less transparentBourges goes further, showing that, given a "primary" hue, one can associate three other hues:
getRelated()
)getCompliment()
)getCompliment().getRelated()
)ColorScheme
.
The first ten hues are "warm" (see isWarm()
), the latter ten are
"cool" (see isCool()
). The compliment of a warm hue is always cool
and vice versa, and the related hue of a warm hue is warm and the related
hue of a cool hue is cool. So color schemes (quads of 4 hues as described
above) always have a nice balance: they always contain two warm and two cool
hues.
Copyright (C) 2004 Marsette A. Vona, III
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Modifier and Type | Field and Description |
---|---|
static Hue |
amberHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
blueVioletHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
coralHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
crimsonHue
hue from "Color Bytes" by Jean Bourges
|
private static java.lang.String |
cvsid
CVS id.
|
static Hue |
cyanHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
emraldHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
goldHue
hue from "Color Bytes" by Jean Bourges
|
static double |
HUE_SNAP
If the
where value is closer than this to the
from or to values in interpolateHue(Hue,
Hue, double) then the corresponding endpoint Hue is returned
directly. |
protected static Hue[] |
hues
All 20 hues from "Color Bytes" by Jean Bourges.
|
int |
index
The index of this Hue.
|
static Hue |
leafGreenHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
lemonHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
limeHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
magentaHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
mauveHue
hue from "Color Bytes" by Jean Bourges
|
static float |
MAX_ALPHA
Maximum typical alpha value.
|
static float |
MAX_BLACK
Maximum typical black value.
|
static float |
MAX_TINT
Maximum typical tint value.
|
int |
maxB
The blue component of the maximum Hue color, in the range [0, 255].
|
int |
maxG
The green component of the maximum Hue color, in the range [0,
255].
|
int |
maxR
The red component of the maximum Hue color, in the range [0, 255].
|
java.awt.Color |
maxTint
|
static float |
MIN_ALPHA
Minimum typical alpha value.
|
static float |
MIN_BLACK
Minimum typical black value.
|
static float |
MIN_TINT
Minimum typical tint value.
|
int |
minB
The blue component of the minimum Hue color, in the range [0, 255].
|
int |
minG
The green component of the minimum Hue color, in the range [0,
255].
|
int |
minR
The red component of the minimum Hue color, in the range [0, 255].
|
java.awt.Color |
minTint
|
java.lang.String |
name
The name of this Hue.
|
static Hue |
orangeHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
posterRedHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
purpleHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
scarletHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
seaGreenHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
skyBlueHue
hue from "Color Bytes" by Jean Bourges
|
static java.awt.color.ColorSpace |
sRGBSpace
The sRGB ColorSpace from
ColorSpace.getInstance(ColorSpace.CS_sRGB) . |
static Hue |
tealHue
hue from "Color Bytes" by Jean Bourges
|
static Hue |
ultramarineHue
hue from "Color Bytes" by Jean Bourges
|
Modifier | Constructor and Description |
---|---|
protected |
Hue(int index,
java.lang.String name,
int maxR,
int maxG,
int maxB)
covers full constructor, uses 255 for min tint components
|
protected |
Hue(int index,
java.lang.String name,
int maxR,
int maxG,
int maxB,
int minR,
int minG,
int minB)
Create a new Hue.
|
Modifier and Type | Method and Description |
---|---|
static java.awt.Color |
convertColor(java.awt.Color color,
java.awt.color.ColorSpace toSpace)
Convert
color to toSpace . |
static java.awt.Color |
convertColor(java.awt.Color color,
int toSpace)
Same as
convertColor(Color, ColorSpace) but gets the target
ColorSpace from ColorSpace.getInstance(toSpace) . |
boolean |
equals(java.lang.Object o)
Check whether this Hue equals another Object.
|
java.awt.Color |
getColor()
Cover of
getMaxTint() . |
java.awt.Color |
getColor(java.awt.color.ColorSpace colorSpace,
float relTint)
Same as
getColor(ColorSpace, float, float) but uses 0.0
black. |
java.awt.Color |
getColor(java.awt.color.ColorSpace colorSpace,
float relTint,
float relBlack)
Same as
getColor(ColorSpace, float, float, float) but uses
1.0 alpha. |
java.awt.Color |
getColor(java.awt.color.ColorSpace colorSpace,
float relTint,
float relBlack,
float relAlpha)
Get a Color associated with this Hue by specifying the tint, black and
alpha attributes.
|
java.awt.Color |
getColor(float relTint)
Same as
getColor(ColorSpace, float) but uses default
ColorSpace. |
java.awt.Color |
getColor(float relTint,
float relBlack)
Same as
getColor(ColorSpace, float, float) but uses default
ColorSpace. |
java.awt.Color |
getColor(float relTint,
float relBlack,
float relAlpha)
Same as
getColor(ColorSpace, float, float, float) but uses
default ColorSpace. |
Hue |
getCompliment()
Get the "complimentary" Hue to this one.
|
static Hue |
getHue(double where)
Get an arbitrary Hue.
|
static Hue |
getHue(int index)
Get one of the
getNumHues() hues by index. |
static Hue |
getHue(java.lang.String name)
Get one of the hues by name.
|
int |
getIndex()
Get the index of this Hue.
|
java.awt.Color |
getMaxTint()
|
java.awt.Color |
getMinTint()
|
java.lang.String |
getName()
Get the name of this Hue.
|
static int |
getNumHues()
Get the number of hues available from
getHue(int) . |
Hue |
getRelated()
Get the "related" Hue to this one.
|
static float |
interpolate(float from,
float to,
double where)
Interpolate between
from and to . |
static float |
interpolate(int from,
int to,
double where)
Interpolate between integer components
from and
to . |
static float |
interpolateAlpha(double where)
|
static float |
interpolateBlack(double where)
|
static Hue |
interpolateHue(Hue from,
Hue to,
double where)
Interpolate between two Hues.
|
static int |
interpolateRGB(int from,
int to,
double where)
Interpolate an integer RGB component between
from and
to . |
static float |
interpolateTint(double where)
|
boolean |
isCool()
Check whether this is a "cool" hue.
|
static boolean |
isValidComponent(double c)
Check whether
c is a valid double component in the range
[0.0, 1.0]. |
static boolean |
isValidComponent(float c)
Check whether
c is a valid float component in the range
[0.0, 1.0]. |
static boolean |
isValidComponent(int c)
Check whether
c is a valid integer component in the range
[0, 255]. |
static boolean |
isValidIndex(int index)
Check whether
index is a valid Hue index in the range
[1, 20]. |
boolean |
isWarm()
Check whether this is a "warm" hue.
|
static float |
normalize(int c)
Convert an integer component in the range [0, 255] to a float in the
range [0.0, 1.0].
|
static int |
percent(double value)
Convert a double value in the range [0.0, 1.0] to an integer percent in
the range [0, 100].
|
static int |
percentToComponent(int percent)
Convert a percent in the range [0, 100] to an integer component in the
range [0, 255].
|
java.lang.String |
toString()
Return a human-readable description of this Hue.
|
private static final java.lang.String cvsid
CVS id.
public static final float MIN_TINT
Minimum typical tint value.
public static final float MAX_TINT
Maximum typical tint value.
public static final float MIN_BLACK
Minimum typical black value.
public static final float MAX_BLACK
Maximum typical black value.
public static final float MIN_ALPHA
Minimum typical alpha value.
public static final float MAX_ALPHA
Maximum typical alpha value.
public static final double HUE_SNAP
If the where
value is closer than this to the
from
or to
values in interpolateHue(Hue,
Hue, double)
then the corresponding endpoint Hue is returned
directly.
public static final Hue mauveHue
public static final Hue magentaHue
public static final Hue crimsonHue
public static final Hue scarletHue
public static final Hue posterRedHue
public static final Hue coralHue
public static final Hue orangeHue
public static final Hue amberHue
public static final Hue goldHue
public static final Hue lemonHue
public static final Hue limeHue
public static final Hue leafGreenHue
public static final Hue seaGreenHue
public static final Hue emraldHue
public static final Hue tealHue
public static final Hue cyanHue
public static final Hue skyBlueHue
public static final Hue ultramarineHue
public static final Hue blueVioletHue
public static final Hue purpleHue
protected static final Hue[] hues
All 20 hues from "Color Bytes" by Jean Bourges.
public static final java.awt.color.ColorSpace sRGBSpace
The sRGB ColorSpace from
ColorSpace.getInstance(ColorSpace.CS_sRGB)
.
public final int index
The index of this Hue.
TBD switch this to a double to better handle interpolated huespublic final java.lang.String name
The name of this Hue.
public final int maxR
The red component of the maximum Hue color, in the range [0, 255].
public final int maxG
The green component of the maximum Hue color, in the range [0, 255].
public final int maxB
The blue component of the maximum Hue color, in the range [0, 255].
public final int minR
The red component of the minimum Hue color, in the range [0, 255].
public final int minG
The green component of the minimum Hue color, in the range [0, 255].
public final int minB
The blue component of the minimum Hue color, in the range [0, 255].
public final java.awt.Color maxTint
public final java.awt.Color minTint
protected Hue(int index, java.lang.String name, int maxR, int maxG, int maxB, int minR, int minG, int minB)
Create a new Hue.
Protected: get Hues from getHue(int)
, getHue(double)
,
or interpolateHue(vona.color.Hue, vona.color.Hue, double)
.
index
- the index of this hue, 1-based, corresponding to the list of
20 hues from "Color Bytes" by Jean Bourgesname
- the name of the HuemaxR
- the red component of the maximum Hue color, in the range [0,
255]maxG
- the green component of the maximum Hue color, in the range [0,
255]maxB
- the blue component of the maximum Hue color, in the range [0,
255]minR
- the red component of the minimum Hue color, in the range [0,
255]minG
- the green component of the minimum Hue color, in the range [0,
255]minB
- the blue component of the maximum Hue color, in the range [0,
255]protected Hue(int index, java.lang.String name, int maxR, int maxG, int maxB)
public static java.awt.Color convertColor(java.awt.Color color, int toSpace)
Same as convertColor(Color, ColorSpace)
but gets the target
ColorSpace from ColorSpace.getInstance(toSpace)
.
toSpace
- identifies the target ColorSpacepublic static java.awt.Color convertColor(java.awt.Color color, java.awt.color.ColorSpace toSpace)
Convert color
to toSpace
.
color
- the color to convert, not nulltoSpace
- the target ColorSpace, if null sRGBSpace
is usedtoSpace
, unless the
ColorSpace of the input color
was already
toSpace
, in which case a reference to the input
color
is returnedpublic static boolean isValidIndex(int index)
Check whether index
is a valid Hue index in the range
[1, 20].
index
- the index to checkindex
is a valid Hue index in the range [1,
20]public static boolean isValidComponent(int c)
Check whether c
is a valid integer component in the range
[0, 255].
c
- the component to checkc
is a valid integer component in the range
[0, 255]public static boolean isValidComponent(float c)
Check whether c
is a valid float component in the range
[0.0, 1.0].
c
- the component to checkc
is a valid float component in the range
[0.0, 1.0]public static boolean isValidComponent(double c)
Check whether c
is a valid double component in the range
[0.0, 1.0].
c
- the component to checkc
is a valid double component in the range
[0.0, 1.0]public static float normalize(int c)
Convert an integer component in the range [0, 255] to a float in the range [0.0, 1.0].
c
- the integer to convertpublic static float interpolate(int from, int to, double where)
Interpolate between integer components from
and
to
.
from
- the start point of interpolation, in the range [0, 255], will
be normalize(int)
dto
- the end point of interpolation, in the range [0, 255], will be
normalize()
dwhere
- the interpolation pointwhere
between from
and to
public static float interpolate(float from, float to, double where)
Interpolate between from
and to
.
from
- the start point of interpolationto
- the end point of interpolationwhere
- the interpolation pointwhere
between from
and to
public static int interpolateRGB(int from, int to, double where)
Interpolate an integer RGB component between from
and
to
.
from
- the start point of interpolationto
- the end point of interpolationwhere
- the interpolation pointwhere
between from
and to
public static float interpolateTint(double where)
interpolate(int, int, double)
between MIN_TINT
and MAX_TINT
.
where
- the interpolation pointwhere
between MIN_TINT and MAX_TINTpublic static float interpolateBlack(double where)
interpolate(int, int, double)
between MIN_BLACK
and MAX_BLACK
.
where
- the interpolation pointwhere
between MIN_BLACK and MAX_BLACKpublic static float interpolateAlpha(double where)
interpolate(int, int, double)
between MIN_ALPHA
and MAX_ALPHA
.
where
- the interpolation pointwhere
between MIN_ALPHA and MAX_ALPHApublic static int percent(double value)
Convert a double value in the range [0.0, 1.0] to an integer percent in the range [0, 100].
value
- the value to convertpublic static int percentToComponent(int percent)
Convert a percent in the range [0, 100] to an integer component in the range [0, 255].
percent
- the percent to convertpublic static Hue getHue(int index)
Get one of the getNumHues()
hues by index.
The first hue is at index 1 in conformance with the Bourges numbering.
index
- the one-based index of the hue in the range [1, getNumHues()
]public static int getNumHues()
Get the number of hues available from getHue(int)
.
getHue(int)
public static Hue getHue(java.lang.String name)
Get one of the hues by name.
name
- the name of the huepublic static Hue getHue(double where)
Get an arbitrary Hue.
where
- a normalized index in the range [0.0, 1.0]where
is closer than HUE_SNAP
to one of
the 20 hues from "Color Bytes" by Jean Bourges, return a reference to that
Hue. Otherwise a new Hue is interpolated, see interpolateHue(vona.color.Hue, vona.color.Hue, double)
public static Hue interpolateHue(Hue from, Hue to, double where)
Interpolate between two Hues.
from
- the bottom hueto
- the top huewhere
- the interpolation pointfrom
and to
, unless where
value is closer than HUE_SNAP
to from
or to
value, in which case
the corresponding endpoint Hue is returned directlypublic java.awt.Color getColor(java.awt.color.ColorSpace colorSpace, float relTint, float relBlack, float relAlpha)
Get a Color associated with this Hue by specifying the tint, black and alpha attributes.
colorSpace
- the ColorSpace in which to return the color, if null
then sRGBSpace
relTint
- the relative tint, i.e. between minTint
and
maxTint
, in the range [0.0, 1.0]relBlack
- the relative black, i.e. between MIN_BLACK
and MAX_BLACK
, in the range [0.0, 1.0]relAlpha
- the relative alpha, i.e. between MIN_ALPHA
and MAX_ALPHA
, in the range [0.0, 1.0]public java.awt.Color getColor(float relTint, float relBlack, float relAlpha)
Same as getColor(ColorSpace, float, float, float)
but uses
default ColorSpace.
public java.awt.Color getColor(java.awt.color.ColorSpace colorSpace, float relTint, float relBlack)
Same as getColor(ColorSpace, float, float, float)
but uses
1.0 alpha.
public java.awt.Color getColor(float relTint, float relBlack)
Same as getColor(ColorSpace, float, float)
but uses default
ColorSpace.
public java.awt.Color getColor(java.awt.color.ColorSpace colorSpace, float relTint)
Same as getColor(ColorSpace, float, float)
but uses 0.0
black.
public java.awt.Color getColor(float relTint)
Same as getColor(ColorSpace, float)
but uses default
ColorSpace.
public java.awt.Color getColor()
Cover of getMaxTint()
.
public java.awt.Color getMaxTint()
public java.awt.Color getMinTint()
public int getIndex()
Get the index of this Hue.
public java.lang.String getName()
Get the name of this Hue.
public java.lang.String toString()
Return a human-readable description of this Hue.
toString
in class java.lang.Object
public boolean isWarm()
Check whether this is a "warm" hue.
public boolean isCool()
Check whether this is a "cool" hue.
public Hue getCompliment()
Get the "complimentary" Hue to this one.
Works only if this is one of the 20 hues from "Color Bytes" by Jean Bourges (i.e. iff this is not an interpolated Hue).
public Hue getRelated()
Get the "related" Hue to this one.
Works only if this is one of the 20 hues from "Color Bytes" by Jean Bourges (i.e. iff this is not an interpolated Hue).