Class Color
java.lang.Object
org.wpilib.util.Color
Represents colors.
Limited to 12 bits of precision.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents a color channel in an RGB color. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Color0xF0F8FF.static final Color0xFAEBD7.static final Color0x00FFFF.static final Color0x7FFFD4.static final Color0xF0FFFF.static final Color0xF5F5DC.static final Color0xFFE4C4.static final Color0x000000.static final Color0xFFEBCD.final doubleBlue component (0-1).static final Color0x0000FF.static final Color0x8A2BE2.static final Color0xA52A2A.static final Color0xDEB887.static final Color0x5F9EA0.static final Color0x7FFF00.static final Color0xD2691E.static final Color0xFF7F50.static final Color0x6495ED.static final Color0xFFF8DC.static final Color0xDC143C.static final Color0x00FFFF.static final Color0x00008B.static final Color0x008B8B.static final Color0xB8860B.static final Color0xA9A9A9.static final Color0x006400.static final Color0xBDB76B.static final Color0x8B008B.static final Color0x556B2F.static final Color0xFF8C00.static final Color0x9932CC.static final Color0x8B0000.static final Color0xE9967A.static final Color0x8FBC8F.static final Color0x483D8B.static final Color0x2F4F4F.static final Color0x00CED1.static final Color0x9400D3.static final Color0xFF1493.static final Color0x00BFFF.static final Color0x1560BD.static final Color0x696969.static final Color0x1E90FF.static final Color0xB22222.static final Color0x0066B3.static final Color0xED1C24.static final Color0xFFFAF0.static final Color0x228B22.static final Color0xFF00FF.static final Color0xDCDCDC.static final Color0xF8F8FF.static final Color0xFFD700.static final Color0xDAA520.static final Color0x808080.final doubleGreen component (0-1).static final Color0x008000.static final Color0xADFF2F.static final Color0xF0FFF0.static final Color0xFF69B4.static final Color0xCD5C5C.static final Color0x4B0082.static final Color0xFFFFF0.static final Color0xF0E68C.static final Color0xE6E6FA.static final Color0xFFF0F5.static final Color0x7CFC00.static final Color0xFFFACD.static final Color0xADD8E6.static final Color0xF08080.static final Color0xE0FFFF.static final Color0xFAFAD2.static final Color0xD3D3D3.static final Color0x90EE90.static final Color0xFFB6C1.static final Color0xFFA07A.static final Color0x20B2AA.static final Color0x87CEFA.static final Color0x778899.static final Color0xB0C4DE.static final Color0xFFFFE0.static final Color0x00FF00.static final Color0x32CD32.static final Color0xFAF0E6.static final Color0xFF00FF.static final Color0x800000.static final Color0x66CDAA.static final Color0x0000CD.static final Color0xBA55D3.static final Color0x9370DB.static final Color0x3CB371.static final Color0x7B68EE.static final Color0x00FA9A.static final Color0x48D1CC.static final Color0xC71585.static final Color0x191970.static final Color0xF5FFFA.static final Color0xFFE4E1.static final Color0xFFE4B5.static final Color0xFFDEAD.static final Color0x000080.static final Color0xFDF5E6.static final Color0x808000.static final Color0x6B8E23.static final Color0xFFA500.static final Color0xFF4500.static final Color0xDA70D6.static final Color0xEEE8AA.static final Color0x98FB98.static final Color0xAFEEEE.static final Color0xDB7093.static final Color0xFFEFD5.static final Color0xFFDAB9.static final Color0xCD853F.static final Color0xFFC0CB.static final Color0xDDA0DD.static final Color0xB0E0E6.static final Color0x800080.final doubleRed component (0-1).static final Color0xFF0000.static final Color0xBC8F8F.static final Color0x4169E1.static final Color0x8B4513.static final Color0xFA8072.static final Color0xF4A460.static final Color0x2E8B57.static final Color0xFFF5EE.static final Color0xA0522D.static final Color0xC0C0C0.static final Color0x87CEEB.static final Color0x6A5ACD.static final Color0x708090.static final Color0xFFFAFA.static final Color0x00FF7F.static final Color0x4682B4.static final Color0xD2B48C.static final Color0x008080.static final Color0xD8BFD8.static final Color0xFF6347.static final Color0x40E0D0.static final Color0xEE82EE.static final Color0xF5DEB3.static final Color0xFFFFFF.static final Color0xF5F5F5.static final Color0xFFFF00.static final Color0x9ACD32. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic ColorfromHSV(int h, int s, int v) Creates a Color from HSV values.static ColorfromString(String str) Makes a Color from a string.inthashCode()static inthsvToRgb(int h, int s, int v) Converts HSV values to RGB values.static intlerpRGB(double r1, double g1, double b1, double r2, double g2, double b2, double t) Linearly interpolates between two RGB colors represented by the (r1, g1, b1) and (r2, g2, b2) triplets.static intlerpRGB(int r1, int g1, int b1, int r2, int g2, int b2, double t) Linearly interpolates between two RGB colors represented by the (r1, g1, b1) and (r2, g2, b2) triplets.static ColorPerforms a linear interpolation between two colors in the RGB colorspace.static intpackRGB(int r, int g, int b) Packs 3 RGB values into a single 32-bit integer.Return this color represented as a hex string.toString()static intunpackRGB(int packedColor, Color.RGBChannel channel) Unpacks a single color channel from a packed 32-bit RGB integer.
-
Field Details
-
red
public final double redRed component (0-1). -
green
public final double greenGreen component (0-1). -
blue
public final double blueBlue component (0-1). -
DENIM
0x1560BD. -
FIRST_BLUE
0x0066B3. -
FIRST_RED
0xED1C24. -
ALICE_BLUE
0xF0F8FF. -
ANTIQUE_WHITE
0xFAEBD7. -
AQUA
0x00FFFF. -
AQUAMARINE
0x7FFFD4. -
AZURE
0xF0FFFF. -
BEIGE
0xF5F5DC. -
BISQUE
0xFFE4C4. -
BLACK
0x000000. -
BLANCHED_ALMOND
0xFFEBCD. -
BLUE
0x0000FF. -
BLUE_VIOLET
0x8A2BE2. -
BROWN
0xA52A2A. -
BURLYWOOD
0xDEB887. -
CADET_BLUE
0x5F9EA0. -
CHARTREUSE
0x7FFF00. -
CHOCOLATE
0xD2691E. -
CORAL
0xFF7F50. -
CORNFLOWER_BLUE
0x6495ED. -
CORNSILK
0xFFF8DC. -
CRIMSON
0xDC143C. -
CYAN
0x00FFFF. -
DARK_BLUE
0x00008B. -
DARK_CYAN
0x008B8B. -
DARK_GOLDENROD
0xB8860B. -
DARK_GRAY
0xA9A9A9. -
DARK_GREEN
0x006400. -
DARK_KHAKI
0xBDB76B. -
DARK_MAGENTA
0x8B008B. -
DARK_OLIVE_GREEN
0x556B2F. -
DARK_ORANGE
0xFF8C00. -
DARK_ORCHID
0x9932CC. -
DARK_RED
0x8B0000. -
DARK_SALMON
0xE9967A. -
DARK_SEA_GREEN
0x8FBC8F. -
DARK_SLATE_BLUE
0x483D8B. -
DARK_SLATE_GRAY
0x2F4F4F. -
DARK_TURQUOISE
0x00CED1. -
DARK_VIOLET
0x9400D3. -
DEEP_PINK
0xFF1493. -
DEEP_SKY_BLUE
0x00BFFF. -
DIM_GRAY
0x696969. -
DODGER_BLUE
0x1E90FF. -
FIREBRICK
0xB22222. -
FLORAL_WHITE
0xFFFAF0. -
FOREST_GREEN
0x228B22. -
FUCHSIA
0xFF00FF. -
GAINSBORO
0xDCDCDC. -
GHOST_WHITE
0xF8F8FF. -
GOLD
0xFFD700. -
GOLDENROD
0xDAA520. -
GRAY
0x808080. -
GREEN
0x008000. -
GREEN_YELLOW
0xADFF2F. -
HONEYDEW
0xF0FFF0. -
HOT_PINK
0xFF69B4. -
INDIAN_RED
0xCD5C5C. -
INDIGO
0x4B0082. -
IVORY
0xFFFFF0. -
KHAKI
0xF0E68C. -
LAVENDER
0xE6E6FA. -
LAVENDER_BLUSH
0xFFF0F5. -
LAWN_GREEN
0x7CFC00. -
LEMON_CHIFFON
0xFFFACD. -
LIGHT_BLUE
0xADD8E6. -
LIGHT_CORAL
0xF08080. -
LIGHT_CYAN
0xE0FFFF. -
LIGHT_GOLDENROD_YELLOW
0xFAFAD2. -
LIGHT_GRAY
0xD3D3D3. -
LIGHT_GREEN
0x90EE90. -
LIGHT_PINK
0xFFB6C1. -
LIGHT_SALMON
0xFFA07A. -
LIGHT_SEA_GREEN
0x20B2AA. -
LIGHT_SKY_BLUE
0x87CEFA. -
LIGHT_SLATE_GRAY
0x778899. -
LIGHT_STEEL_BLUE
0xB0C4DE. -
LIGHT_YELLOW
0xFFFFE0. -
LIME
0x00FF00. -
LIME_GREEN
0x32CD32. -
LINEN
0xFAF0E6. -
MAGENTA
0xFF00FF. -
MAROON
0x800000. -
MEDIUM_AQUAMARINE
0x66CDAA. -
MEDIUM_BLUE
0x0000CD. -
MEDIUM_ORCHID
0xBA55D3. -
MEDIUM_PURPLE
0x9370DB. -
MEDIUM_SEA_GREEN
0x3CB371. -
MEDIUM_SLATE_BLUE
0x7B68EE. -
MEDIUM_SPRING_GREEN
0x00FA9A. -
MEDIUM_TURQUOISE
0x48D1CC. -
MEDIUM_VIOLET_RED
0xC71585. -
MIDNIGHT_BLUE
0x191970. -
MINTCREAM
0xF5FFFA. -
MISTY_ROSE
0xFFE4E1. -
MOCCASIN
0xFFE4B5. -
NAVAJO_WHITE
0xFFDEAD. -
NAVY
0x000080. -
OLD_LACE
0xFDF5E6. -
OLIVE
0x808000. -
OLIVE_DRAB
0x6B8E23. -
ORANGE
0xFFA500. -
ORANGE_RED
0xFF4500. -
ORCHID
0xDA70D6. -
PALE_GOLDENROD
0xEEE8AA. -
PALE_GREEN
0x98FB98. -
PALE_TURQUOISE
0xAFEEEE. -
PALE_VIOLET_RED
0xDB7093. -
PAPAYA_WHIP
0xFFEFD5. -
PEACH_PUFF
0xFFDAB9. -
PERU
0xCD853F. -
PINK
0xFFC0CB. -
PLUM
0xDDA0DD. -
POWDER_BLUE
0xB0E0E6. -
PURPLE
0x800080. -
RED
0xFF0000. -
ROSY_BROWN
0xBC8F8F. -
ROYAL_BLUE
0x4169E1. -
SADDLE_BROWN
0x8B4513. -
SALMON
0xFA8072. -
SANDY_BROWN
0xF4A460. -
SEA_GREEN
0x2E8B57. -
SEASHELL
0xFFF5EE. -
SIENNA
0xA0522D. -
SILVER
0xC0C0C0. -
SKY_BLUE
0x87CEEB. -
SLATE_BLUE
0x6A5ACD. -
SLATE_GRAY
0x708090. -
SNOW
0xFFFAFA. -
SPRING_GREEN
0x00FF7F. -
STEEL_BLUE
0x4682B4. -
TAN
0xD2B48C. -
TEAL
0x008080. -
THISTLE
0xD8BFD8. -
TOMATO
0xFF6347. -
TURQUOISE
0x40E0D0. -
VIOLET
0xEE82EE. -
WHEAT
0xF5DEB3. -
WHITE
0xFFFFFF. -
WHITE_SMOKE
0xF5F5F5. -
YELLOW
0xFFFF00. -
YELLOW_GREEN
0x9ACD32.
-
-
Constructor Details
-
Color
public Color()Constructs a default color (black). -
Color
public Color(double red, double green, double blue) Constructs a Color from doubles.- Parameters:
red- Red value (0-1)green- Green value (0-1)blue- Blue value (0-1)
-
Color
public Color(int red, int green, int blue) Constructs a Color from ints.- Parameters:
red- Red value (0-255)green- Green value (0-255)blue- Blue value (0-255)
-
Color
-
-
Method Details
-
fromString
Makes a Color from a string.- Parameters:
str- a string of the format#RRGGBB,rgb(R, G, B), orConstantName- Returns:
- the Color
- Throws:
IllegalArgumentException- if the string is invalid.
-
fromHSV
Creates a Color from HSV values.- Parameters:
h- The h value [0-180)s- The s value [0-255]v- The v value [0-255]- Returns:
- The color
-
equals
-
hashCode
-
toString
-
toHexString
Return this color represented as a hex string.- Returns:
- a string of the format
#RRGGBB
-
hsvToRgb
public static int hsvToRgb(int h, int s, int v) Converts HSV values to RGB values. The returned RGB color is packed into a 32-bit integer for memory performance reasons.- Parameters:
h- The h value [0-180)s- The s value [0-255]v- The v value [0-255]- Returns:
- the packed RGB color
-
packRGB
public static int packRGB(int r, int g, int b) Packs 3 RGB values into a single 32-bit integer. These values can be unpacked withunpackRGB(int, RGBChannel)to retrieve the values. This is helpful for avoiding memory allocations of newColorobjects and its resulting garbage collector pressure.- Parameters:
r- the value of the first channel to packg- the value of the second channel to packb- the value of the third channel to pack- Returns:
- the packed integer
-
unpackRGB
Unpacks a single color channel from a packed 32-bit RGB integer.Note: Packed RGB colors are expected to be in byte order [empty][red][green][blue].
- Parameters:
packedColor- the packed color to extract fromchannel- the color channel to unpack- Returns:
- the value of the stored color channel
-
lerpRGB
-
lerpRGB
public static int lerpRGB(double r1, double g1, double b1, double r2, double g2, double b2, double t) Linearly interpolates between two RGB colors represented by the (r1, g1, b1) and (r2, g2, b2) triplets. For memory performance reasons, the output color is returned packed into a single 32-bit integer; useunpackRGB(int, RGBChannel)to extract the values for the individual red, green, and blue channels.- Parameters:
r1- the red value of the first color, in [0, 1]g1- the green value of the first color, in [0, 1]b1- the blue value of the first color, in [0, 1]r2- the red value of the second color, in [0, 1]g2- the green value of the second color, in [0, 1]b2- the blue value of the second color, in [0, 1]t- the interpolation value, in [0, 1]- Returns:
- the interpolated color, packed in a 32-bit integer
-
lerpRGB
public static int lerpRGB(int r1, int g1, int b1, int r2, int g2, int b2, double t) Linearly interpolates between two RGB colors represented by the (r1, g1, b1) and (r2, g2, b2) triplets. For memory performance reasons, the output color is returned packed into a single 32-bit integer; useunpackRGB(int, RGBChannel)to extract the values for the individual red, green, and blue channels.- Parameters:
r1- the red value of the first color, in [0, 255]g1- the green value of the first color, in [0, 255]b1- the blue value of the first color, in [0, 255]r2- the red value of the second color, in [0, 255]g2- the green value of the second color, in [0, 255]b2- the blue value of the second color, in [0, 255]t- the interpolation value, in [0, 1]- Returns:
- the interpolated color, packed in a 32-bit integer
-