Package snap.gfx
Class Color
java.lang.Object
snap.gfx.Color
- All Implemented Interfaces:
Paint
,XMLArchiver.Archivable
This class represents an RGBA color.
-
Field Summary
Modifier and TypeFieldDescriptionstatic Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
static Color
-
Constructor Summary
ConstructorDescriptionColor()
Creates a plain black opaque color.Color
(double g) Creates a color with the given gray value (0-1).Color
(double g, double a) Creates a color with the given gray and alpha values (0-1).Color
(double r, double g, double b) Creates a color with the given red, green blue values (0-1).Color
(double r, double g, double b, double a) Creates a color with the given red, green, blue values (0-1).Color
(double c, double m, double y, double k, double a) Creates a color with the given cyan, magenta, yellow, black and alpha values (0-1).Color
(int aRGBA) Creates a plain black opaque color.Color
(int r, int g, int b) Creates a color with the given red, green blue values (0-1).Color
(int r, int g, int b, int a) Creates a color with the given red, green blue values (0-1).Creates a new color from the given hex string.Color
(ColorSpace aCS, float[] comps, double alpha) Creates a new Color from given ColorSpace, components array and alpha. -
Method Summary
Modifier and TypeMethodDescriptionReturns a color darker than this color (by this given fraction).brighter()
Returns a color brighter than this color (blended with white).copyForAlpha
(double anAlpha) Returns a copy of this paint modified for given color.copyForColor
(Color aColor) Returns a copy of this paint modified for given color.copyForRect
(Rect aRect) Returns an absolute paint for given bounds of primitive to be filled.darker()
Returns a color darker than this color (blended with black).boolean
Standard equals implementation.fromXML
(XMLArchiver anArchiver, XMLElement anElement) XML unarchival.static Color
Returns a color value for a given object.double
getAlpha()
Returns the alpha component in the range 0-1.int
Returns the alpha component in the range 0-255.double
getBlue()
Returns the blue component in the range 0-1.int
Returns the blue component in the range 0-255.getColor()
Returns the closest color approximation of this paint.float[]
getColorComponents
(ColorSpace cspace, float[] compArray) Returns a float array containing only the color components of the Color in the ColorSpace specified by the cspace parameter.Returns the ColorSpace of this Color.float[]
float[]
getComponents
(ColorSpace cspace, float[] compArray) Returns a float array containing the color and alpha components of the Color, in the ColorSpace specified by cspace parameter.double
getGreen()
Returns the green component in the range 0-1.int
Returns the green component in the range 0-255.static Color
Returns a random color.double
getRed()
Returns the red component in the range 0-1.int
Returns the red component in the range 0-255.int
getRGB()
Returns the color as an int.int
getRGBA()
Returns the color as an int.int
hashCode()
Standard Hashcode implementation.boolean
Returns whether paint is defined in terms independent of primitive to be filled.boolean
isOpaque()
Returns whether paint is opaque.Returns a hex string representation of this color.toString()
Returns a string representation of this color.toXML
(XMLArchiver anArchiver) XML archival.
-
Field Details
-
BLACK
-
BLUE
-
CYAN
-
DARKGRAY
-
GRAY
-
GREEN
-
LIGHTGRAY
-
MAGENTA
-
ORANGE
-
PINK
-
RED
-
WHITE
-
YELLOW
-
CLEAR
-
LIGHTBLUE
-
CLEARWHITE
-
CRIMSON
-
GRAY1
-
GRAY2
-
GRAY3
-
GRAY4
-
GRAY5
-
GRAY6
-
GRAY7
-
GRAY8
-
GRAY9
-
-
Constructor Details
-
Color
public Color()Creates a plain black opaque color. -
Color
public Color(int aRGBA) Creates a plain black opaque color. -
Color
public Color(double g) Creates a color with the given gray value (0-1). -
Color
public Color(double g, double a) Creates a color with the given gray and alpha values (0-1). -
Color
public Color(double r, double g, double b) Creates a color with the given red, green blue values (0-1). -
Color
public Color(int r, int g, int b) Creates a color with the given red, green blue values (0-1). -
Color
public Color(int r, int g, int b, int a) Creates a color with the given red, green blue values (0-1). -
Color
public Color(double r, double g, double b, double a) Creates a color with the given red, green, blue values (0-1). -
Color
public Color(double c, double m, double y, double k, double a) Creates a color with the given cyan, magenta, yellow, black and alpha values (0-1). Bogus right now. -
Color
Creates a new color from the given hex string. -
Color
Creates a new Color from given ColorSpace, components array and alpha.
-
-
Method Details
-
getRed
public double getRed()Returns the red component in the range 0-1. -
getGreen
public double getGreen()Returns the green component in the range 0-1. -
getBlue
public double getBlue()Returns the blue component in the range 0-1. -
getAlpha
public double getAlpha()Returns the alpha component in the range 0-1. -
getRedInt
public int getRedInt()Returns the red component in the range 0-255. -
getGreenInt
public int getGreenInt()Returns the green component in the range 0-255. -
getBlueInt
public int getBlueInt()Returns the blue component in the range 0-255. -
getAlphaInt
public int getAlphaInt()Returns the alpha component in the range 0-255. -
getRGB
public int getRGB()Returns the color as an int. -
getRGBA
public int getRGBA()Returns the color as an int. -
brighter
Returns a color brighter than this color (blended with white). -
darker
Returns a color darker than this color (blended with black). -
blend
Returns a color darker than this color (by this given fraction). -
isAbsolute
public boolean isAbsolute()Returns whether paint is defined in terms independent of primitive to be filled.- Specified by:
isAbsolute
in interfacePaint
-
isOpaque
public boolean isOpaque()Returns whether paint is opaque. -
getColor
Returns the closest color approximation of this paint. -
copyForColor
Returns a copy of this paint modified for given color.- Specified by:
copyForColor
in interfacePaint
-
copyForAlpha
Returns a copy of this paint modified for given color. -
copyForRect
Returns an absolute paint for given bounds of primitive to be filled.- Specified by:
copyForRect
in interfacePaint
-
equals
Standard equals implementation. -
hashCode
public int hashCode()Standard Hashcode implementation. -
toString
Returns a string representation of this color. -
toHexString
Returns a hex string representation of this color. -
getComponents
Returns a float array containing the color and alpha components of the Color, in the ColorSpace specified by cspace parameter. If compArray is null, an array with length equal to number of components in cspace plus one is created. -
getColorComponents
Returns a float array containing only the color components of the Color in the ColorSpace specified by the cspace parameter. If compArray is null, an array with length equal to the number of components in cspace is created. -
getColorSpace
Returns the ColorSpace of this Color. -
getComponents
public float[] getComponents() -
get
Returns a color value for a given object. -
getRandom
Returns a random color. -
toXML
XML archival.- Specified by:
toXML
in interfaceXMLArchiver.Archivable
-
fromXML
XML unarchival.- Specified by:
fromXML
in interfaceXMLArchiver.Archivable
-