Class Color

java.lang.Object
org.wpilib.util.Color

public class Color extends Object
Represents colors.

Limited to 12 bits of precision.

  • Field Details

    • red

      public final double red
      Red component (0-1).
    • green

      public final double green
      Green component (0-1).
    • blue

      public final double blue
      Blue component (0-1).
    • DENIM

      public static final Color DENIM
      0x1560BD.
    • FIRST_BLUE

      public static final Color FIRST_BLUE
      0x0066B3.
    • FIRST_RED

      public static final Color FIRST_RED
      0xED1C24.
    • ALICE_BLUE

      public static final Color ALICE_BLUE
      0xF0F8FF.
    • ANTIQUE_WHITE

      public static final Color ANTIQUE_WHITE
      0xFAEBD7.
    • AQUA

      public static final Color AQUA
      0x00FFFF.
    • AQUAMARINE

      public static final Color AQUAMARINE
      0x7FFFD4.
    • AZURE

      public static final Color AZURE
      0xF0FFFF.
    • BEIGE

      public static final Color BEIGE
      0xF5F5DC.
    • BISQUE

      public static final Color BISQUE
      0xFFE4C4.
    • BLACK

      public static final Color BLACK
      0x000000.
    • BLANCHED_ALMOND

      public static final Color BLANCHED_ALMOND
      0xFFEBCD.
    • BLUE

      public static final Color BLUE
      0x0000FF.
    • BLUE_VIOLET

      public static final Color BLUE_VIOLET
      0x8A2BE2.
    • BROWN

      public static final Color BROWN
      0xA52A2A.
    • BURLYWOOD

      public static final Color BURLYWOOD
      0xDEB887.
    • CADET_BLUE

      public static final Color CADET_BLUE
      0x5F9EA0.
    • CHARTREUSE

      public static final Color CHARTREUSE
      0x7FFF00.
    • CHOCOLATE

      public static final Color CHOCOLATE
      0xD2691E.
    • CORAL

      public static final Color CORAL
      0xFF7F50.
    • CORNFLOWER_BLUE

      public static final Color CORNFLOWER_BLUE
      0x6495ED.
    • CORNSILK

      public static final Color CORNSILK
      0xFFF8DC.
    • CRIMSON

      public static final Color CRIMSON
      0xDC143C.
    • CYAN

      public static final Color CYAN
      0x00FFFF.
    • DARK_BLUE

      public static final Color DARK_BLUE
      0x00008B.
    • DARK_CYAN

      public static final Color DARK_CYAN
      0x008B8B.
    • DARK_GOLDENROD

      public static final Color DARK_GOLDENROD
      0xB8860B.
    • DARK_GRAY

      public static final Color DARK_GRAY
      0xA9A9A9.
    • DARK_GREEN

      public static final Color DARK_GREEN
      0x006400.
    • DARK_KHAKI

      public static final Color DARK_KHAKI
      0xBDB76B.
    • DARK_MAGENTA

      public static final Color DARK_MAGENTA
      0x8B008B.
    • DARK_OLIVE_GREEN

      public static final Color DARK_OLIVE_GREEN
      0x556B2F.
    • DARK_ORANGE

      public static final Color DARK_ORANGE
      0xFF8C00.
    • DARK_ORCHID

      public static final Color DARK_ORCHID
      0x9932CC.
    • DARK_RED

      public static final Color DARK_RED
      0x8B0000.
    • DARK_SALMON

      public static final Color DARK_SALMON
      0xE9967A.
    • DARK_SEA_GREEN

      public static final Color DARK_SEA_GREEN
      0x8FBC8F.
    • DARK_SLATE_BLUE

      public static final Color DARK_SLATE_BLUE
      0x483D8B.
    • DARK_SLATE_GRAY

      public static final Color DARK_SLATE_GRAY
      0x2F4F4F.
    • DARK_TURQUOISE

      public static final Color DARK_TURQUOISE
      0x00CED1.
    • DARK_VIOLET

      public static final Color DARK_VIOLET
      0x9400D3.
    • DEEP_PINK

      public static final Color DEEP_PINK
      0xFF1493.
    • DEEP_SKY_BLUE

      public static final Color DEEP_SKY_BLUE
      0x00BFFF.
    • DIM_GRAY

      public static final Color DIM_GRAY
      0x696969.
    • DODGER_BLUE

      public static final Color DODGER_BLUE
      0x1E90FF.
    • FIREBRICK

      public static final Color FIREBRICK
      0xB22222.
    • FLORAL_WHITE

      public static final Color FLORAL_WHITE
      0xFFFAF0.
    • FOREST_GREEN

      public static final Color FOREST_GREEN
      0x228B22.
    • FUCHSIA

      public static final Color FUCHSIA
      0xFF00FF.
    • GAINSBORO

      public static final Color GAINSBORO
      0xDCDCDC.
    • GHOST_WHITE

      public static final Color GHOST_WHITE
      0xF8F8FF.
    • GOLD

      public static final Color GOLD
      0xFFD700.
    • GOLDENROD

      public static final Color GOLDENROD
      0xDAA520.
    • GRAY

      public static final Color GRAY
      0x808080.
    • GREEN

      public static final Color GREEN
      0x008000.
    • GREEN_YELLOW

      public static final Color GREEN_YELLOW
      0xADFF2F.
    • HONEYDEW

      public static final Color HONEYDEW
      0xF0FFF0.
    • HOT_PINK

      public static final Color HOT_PINK
      0xFF69B4.
    • INDIAN_RED

      public static final Color INDIAN_RED
      0xCD5C5C.
    • INDIGO

      public static final Color INDIGO
      0x4B0082.
    • IVORY

      public static final Color IVORY
      0xFFFFF0.
    • KHAKI

      public static final Color KHAKI
      0xF0E68C.
    • LAVENDER

      public static final Color LAVENDER
      0xE6E6FA.
    • LAVENDER_BLUSH

      public static final Color LAVENDER_BLUSH
      0xFFF0F5.
    • LAWN_GREEN

      public static final Color LAWN_GREEN
      0x7CFC00.
    • LEMON_CHIFFON

      public static final Color LEMON_CHIFFON
      0xFFFACD.
    • LIGHT_BLUE

      public static final Color LIGHT_BLUE
      0xADD8E6.
    • LIGHT_CORAL

      public static final Color LIGHT_CORAL
      0xF08080.
    • LIGHT_CYAN

      public static final Color LIGHT_CYAN
      0xE0FFFF.
    • LIGHT_GOLDENROD_YELLOW

      public static final Color LIGHT_GOLDENROD_YELLOW
      0xFAFAD2.
    • LIGHT_GRAY

      public static final Color LIGHT_GRAY
      0xD3D3D3.
    • LIGHT_GREEN

      public static final Color LIGHT_GREEN
      0x90EE90.
    • LIGHT_PINK

      public static final Color LIGHT_PINK
      0xFFB6C1.
    • LIGHT_SALMON

      public static final Color LIGHT_SALMON
      0xFFA07A.
    • LIGHT_SEA_GREEN

      public static final Color LIGHT_SEA_GREEN
      0x20B2AA.
    • LIGHT_SKY_BLUE

      public static final Color LIGHT_SKY_BLUE
      0x87CEFA.
    • LIGHT_SLATE_GRAY

      public static final Color LIGHT_SLATE_GRAY
      0x778899.
    • LIGHT_STEEL_BLUE

      public static final Color LIGHT_STEEL_BLUE
      0xB0C4DE.
    • LIGHT_YELLOW

      public static final Color LIGHT_YELLOW
      0xFFFFE0.
    • LIME

      public static final Color LIME
      0x00FF00.
    • LIME_GREEN

      public static final Color LIME_GREEN
      0x32CD32.
    • LINEN

      public static final Color LINEN
      0xFAF0E6.
    • MAGENTA

      public static final Color MAGENTA
      0xFF00FF.
    • MAROON

      public static final Color MAROON
      0x800000.
    • MEDIUM_AQUAMARINE

      public static final Color MEDIUM_AQUAMARINE
      0x66CDAA.
    • MEDIUM_BLUE

      public static final Color MEDIUM_BLUE
      0x0000CD.
    • MEDIUM_ORCHID

      public static final Color MEDIUM_ORCHID
      0xBA55D3.
    • MEDIUM_PURPLE

      public static final Color MEDIUM_PURPLE
      0x9370DB.
    • MEDIUM_SEA_GREEN

      public static final Color MEDIUM_SEA_GREEN
      0x3CB371.
    • MEDIUM_SLATE_BLUE

      public static final Color MEDIUM_SLATE_BLUE
      0x7B68EE.
    • MEDIUM_SPRING_GREEN

      public static final Color MEDIUM_SPRING_GREEN
      0x00FA9A.
    • MEDIUM_TURQUOISE

      public static final Color MEDIUM_TURQUOISE
      0x48D1CC.
    • MEDIUM_VIOLET_RED

      public static final Color MEDIUM_VIOLET_RED
      0xC71585.
    • MIDNIGHT_BLUE

      public static final Color MIDNIGHT_BLUE
      0x191970.
    • MINTCREAM

      public static final Color MINTCREAM
      0xF5FFFA.
    • MISTY_ROSE

      public static final Color MISTY_ROSE
      0xFFE4E1.
    • MOCCASIN

      public static final Color MOCCASIN
      0xFFE4B5.
    • OLD_LACE

      public static final Color OLD_LACE
      0xFDF5E6.
    • OLIVE

      public static final Color OLIVE
      0x808000.
    • OLIVE_DRAB

      public static final Color OLIVE_DRAB
      0x6B8E23.
    • ORANGE

      public static final Color ORANGE
      0xFFA500.
    • ORANGE_RED

      public static final Color ORANGE_RED
      0xFF4500.
    • ORCHID

      public static final Color ORCHID
      0xDA70D6.
    • PALE_GOLDENROD

      public static final Color PALE_GOLDENROD
      0xEEE8AA.
    • PALE_GREEN

      public static final Color PALE_GREEN
      0x98FB98.
    • PALE_TURQUOISE

      public static final Color PALE_TURQUOISE
      0xAFEEEE.
    • PALE_VIOLET_RED

      public static final Color PALE_VIOLET_RED
      0xDB7093.
    • PAPAYA_WHIP

      public static final Color PAPAYA_WHIP
      0xFFEFD5.
    • PEACH_PUFF

      public static final Color PEACH_PUFF
      0xFFDAB9.
    • PERU

      public static final Color PERU
      0xCD853F.
    • PINK

      public static final Color PINK
      0xFFC0CB.
    • PLUM

      public static final Color PLUM
      0xDDA0DD.
    • POWDER_BLUE

      public static final Color POWDER_BLUE
      0xB0E0E6.
    • PURPLE

      public static final Color PURPLE
      0x800080.
    • RED

      public static final Color RED
      0xFF0000.
    • ROSY_BROWN

      public static final Color ROSY_BROWN
      0xBC8F8F.
    • ROYAL_BLUE

      public static final Color ROYAL_BLUE
      0x4169E1.
    • SADDLE_BROWN

      public static final Color SADDLE_BROWN
      0x8B4513.
    • SALMON

      public static final Color SALMON
      0xFA8072.
    • SANDY_BROWN

      public static final Color SANDY_BROWN
      0xF4A460.
    • SEA_GREEN

      public static final Color SEA_GREEN
      0x2E8B57.
    • SEASHELL

      public static final Color SEASHELL
      0xFFF5EE.
    • SIENNA

      public static final Color SIENNA
      0xA0522D.
    • SILVER

      public static final Color SILVER
      0xC0C0C0.
    • SKY_BLUE

      public static final Color SKY_BLUE
      0x87CEEB.
    • SLATE_BLUE

      public static final Color SLATE_BLUE
      0x6A5ACD.
    • SLATE_GRAY

      public static final Color SLATE_GRAY
      0x708090.
    • SNOW

      public static final Color SNOW
      0xFFFAFA.
    • SPRING_GREEN

      public static final Color SPRING_GREEN
      0x00FF7F.
    • STEEL_BLUE

      public static final Color STEEL_BLUE
      0x4682B4.
    • TAN

      public static final Color TAN
      0xD2B48C.
    • TEAL

      public static final Color TEAL
      0x008080.
    • THISTLE

      public static final Color THISTLE
      0xD8BFD8.
    • TOMATO

      public static final Color TOMATO
      0xFF6347.
    • TURQUOISE

      public static final Color TURQUOISE
      0x40E0D0.
    • VIOLET

      public static final Color VIOLET
      0xEE82EE.
    • WHEAT

      public static final Color WHEAT
      0xF5DEB3.
    • WHITE

      public static final Color WHITE
      0xFFFFFF.
    • WHITE_SMOKE

      public static final Color WHITE_SMOKE
      0xF5F5F5.
    • YELLOW

      public static final Color YELLOW
      0xFFFF00.
    • YELLOW_GREEN

      public static final Color 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

      public Color(Color8Bit color)
      Constructs a Color from a Color8Bit.
      Parameters:
      color - The color
  • Method Details

    • fromString

      public static Color fromString(String str)
      Makes a Color from a string.
      Parameters:
      str - a string of the format #RRGGBB, rgb(R, G, B), or ConstantName
      Returns:
      the Color
      Throws:
      IllegalArgumentException - if the string is invalid.
    • fromHSV

      public static Color fromHSV(int h, int s, int v)
      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

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toHexString

      public String 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 with unpackRGB(int, RGBChannel) to retrieve the values. This is helpful for avoiding memory allocations of new Color objects and its resulting garbage collector pressure.
      Parameters:
      r - the value of the first channel to pack
      g - the value of the second channel to pack
      b - the value of the third channel to pack
      Returns:
      the packed integer
    • unpackRGB

      public static int unpackRGB(int packedColor, Color.RGBChannel channel)
      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 from
      channel - the color channel to unpack
      Returns:
      the value of the stored color channel
    • lerpRGB

      public static Color lerpRGB(Color a, Color b, double t)
      Performs a linear interpolation between two colors in the RGB colorspace.
      Parameters:
      a - the first color to interpolate from
      b - the second color to interpolate from
      t - the interpolation scale in [0, 1]
      Returns:
      the interpolated color
    • 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; use unpackRGB(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; use unpackRGB(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