Class Color

The Color class is used to encapsulate colors in the default sRGB color space.
Every color has an implicit alpha value of 1.0 or an explicit one provided
in the constructor. The alpha value defines the transparency of a color
and can be represented by a double value in the range 0.0-1.0 or 0-255.
An alpha value of 1.0 or 255 means that the color is completely opaque
and an alpha value of 0 or 0.0 means that the color is completely transparent.
When constructing a Color with an explicit alpha or getting
the color/alpha components of a Color,
the color components are never premultiplied by the alpha component.

Colors can be created with the constructor or with one of several
utility methods. The following lines of code all create the same
blue color:

web

An HTML long or short format hex string with an optional hex alpha
channel.
Hexadecimal values may be preceded by either "0x" or "#"
and can either be 2 digits in the range 00 to 0xFF or a
single digit in the range 0 to F.

An rgb(r,g,b) or rgba(r,g,b,a) format string.
Each of the r, g, or b values can be an integer
from 0 to 255 or a floating point percentage value from 0.0 to 100.0
followed by the percent (%) character.
The alpha component, if present, is a
floating point value from 0.0 to 1.0. Spaces are allowed before or
after the numbers and between the percentage number and its percent
sign (%).

An hsl(h,s,l) or hsla(h,s,l,a) format string.
The h value is a floating point number from 0.0 to 360.0
representing the hue angle on a color wheel in degrees with
0.0 or 360.0 representing red, 120.0
representing green, and 240.0 representing blue. The
s value is the saturation of the desired color represented
as a floating point percentage from gray (0.0) to
the fully saturated color (100.0) and the l value
is the desired lightness or brightness of the desired color represented
as a floating point percentage from black (0.0) to the full
brightness of the color (100.0).
The alpha component, if present, is a floating
point value from 0.0 to 1.0. Spaces are allowed before or
after the numbers and between the percentage number and its percent
sign (%).

For formats without an alpha component and for named colors, opacity
is set according to the opacity argument. For colors specified
with an alpha component, the resulting opacity is a combination of the
parsed alpha component and the opacity argument, so a
transparent color becomes more transparent by specifying opacity.

Examples:

Web Format String

Equivalent constructor or factory call

Color.web("orange", 0.5);

new Color(1.0, 0xA5/255.0, 0.0, 0.5)

Color.web("0xff66cc33", 0.5);

new Color(1.0, 0.4, 0.8, 0.1)

Color.web("0xff66cc", 0.5);

new Color(1.0, 0.4, 0.8, 0.5)

Color.web("#ff66cc", 0.5);

new Color(1.0, 0.4, 0.8, 0.5)

Color.web("#f68", 0.5);

new Color(1.0, 0.4, 0.8, 0.5)

Color.web("rgb(255,102,204)", 0.5);

new Color(1.0, 0.4, 0.8, 0.5)

Color.web("rgb(100%,50%,50%)", 0.5);

new Color(1.0, 0.5, 0.5, 0.5)

Color.web("rgb(255,50%,50%,0.25)", 0.5);

new Color(1.0, 0.5, 0.5, 0.125)

Color.web("hsl(240,100%,100%)", 0.5);

Color.hsb(240.0, 1.0, 1.0, 0.5)

Color.web("hsla(120,0%,0%,0.25)", 0.5);

Color.hsb(120.0, 0.0, 0.0, 0.125)

Parameters:

colorString - the name or numeric representation of the color
in one of the supported formats

opacity - the opacity component in range from 0.0 (transparent)
to 1.0 (opaque)

web

An HTML long or short format hex string with an optional hex alpha
channel.
Hexadecimal values may be preceded by either "0x" or "#"
and can either be 2 digits in the range 00 to 0xFF or a
single digit in the range 0 to F.

An rgb(r,g,b) or rgba(r,g,b,a) format string.
Each of the r, g, or b values can be an integer
from 0 to 255 or a floating point percentage value from 0.0 to 100.0
followed by the percent (%) character.
The alpha component, if present, is a
floating point value from 0.0 to 1.0. Spaces are allowed before or
after the numbers and between the percentage number and its percent
sign (%).

An hsl(h,s,l) or hsla(h,s,l,a) format string.
The h value is a floating point number from 0.0 to 360.0
representing the hue angle on a color wheel in degrees with
0.0 or 360.0 representing red, 120.0
representing green, and 240.0 representing blue. The
s value is the saturation of the desired color represented
as a floating point percentage from gray (0.0) to
the fully saturated color (100.0) and the l value
is the desired lightness or brightness of the desired color represented
as a floating point percentage from black (0.0) to the full
brightness of the color (100.0).
The alpha component, if present, is a floating
point value from 0.0 to 1.0. Spaces are allowed before or
after the numbers and between the percentage number and its percent
sign (%).

Examples:

Web Format String

Equivalent constant or factory call

Color.web("orange");

Color.ORANGE

Color.web("0xff668840");

Color.rgb(255, 102, 136, 0.25)

Color.web("0xff6688");

Color.rgb(255, 102, 136, 1.0)

Color.web("#ff6688");

Color.rgb(255, 102, 136, 1.0)

Color.web("#f68");

Color.rgb(255, 102, 136, 1.0)

Color.web("rgb(255,102,136)");

Color.rgb(255, 102, 136, 1.0)

Color.web("rgb(100%,50%,50%)");

Color.rgb(255, 128, 128, 1.0)

Color.web("rgb(255,50%,50%,0.25)");

Color.rgb(255, 128, 128, 0.25)

Color.web("hsl(240,100%,100%)");

Color.hsb(240.0, 1.0, 1.0, 1.0)

Color.web("hsla(120,0%,0%,0.25)");

Color.hsb(120.0, 0.0, 0.0, 0.25)

Parameters:

colorString - the name or numeric representation of the color
in one of the supported formats

deriveColor

Creates a new Color based on this Color with hue,
saturation, brightness and opacity values altered. Hue is shifted
about the given value and normalized into its natural range, the
other components' values are multiplied by the given factors and
clipped into their ranges.
Increasing brightness of black color is allowed by using an arbitrary,
very small source brightness instead of zero.

getOpacity

isOpaque

Gets whether this Paint is completely opaque. An opaque paint is one that
has no alpha component in any of its colors. It may be possible for a Paint
to be opaque and yet return false, if it cannot be easily determined
whether the paint is actually opaque. For example, the ImagePattern may not
be able to cheaply determine its opacity.

hashCode

toString

Returns a string representation of this Color.
This method is intended to be used only for informational purposes.
The content and format of the returned string might vary between implementations.
The returned string might be empty but cannot be null.