Package snap.gfx

Class Color

java.lang.Object
snap.gfx.Color
All Implemented Interfaces:
Paint, XMLArchiver.Archivable

public class Color extends Object implements Paint, XMLArchiver.Archivable
This class represents an RGBA color.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    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
     
    static Color
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    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).
    Color(String aHexStr)
    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 Type
    Method
    Description
    blend(Color aColor, double aFraction)
    Returns a color darker than this color (by this given fraction).
    Returns a color brighter than this color (blended with white).
    copyForAlpha(double anAlpha)
    Returns a copy of this paint modified for given color.
    Returns a copy of this paint modified for given color.
    Returns an absolute paint for given bounds of primitive to be filled.
    Returns a color darker than this color (blended with black).
    boolean
    equals(Object anObj)
    Standard equals implementation.
    fromXML(XMLArchiver anArchiver, XMLElement anElement)
    XML unarchival.
    static Color
    get(Object anObj)
    Returns a color value for a given object.
    double
    Returns the alpha component in the range 0-1.
    int
    Returns the alpha component in the range 0-255.
    double
    Returns the blue component in the range 0-1.
    int
    Returns the blue component in the range 0-255.
    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
    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
    Returns the red component in the range 0-1.
    int
    Returns the red component in the range 0-255.
    int
    Returns the color as an int.
    int
    Returns the color as an int.
    int
    Standard Hashcode implementation.
    boolean
    Returns whether paint is defined in terms independent of primitive to be filled.
    boolean
    Returns whether paint is opaque.
    Returns a hex string representation of this color.
    Returns a string representation of this color.
    toXML(XMLArchiver anArchiver)
    XML archival.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface snap.gfx.Paint

    getName, snap
  • Field Details

    • BLACK

      public static Color BLACK
    • BLUE

      public static Color BLUE
    • CYAN

      public static Color CYAN
    • DARKGRAY

      public static Color DARKGRAY
    • GRAY

      public static Color GRAY
    • GREEN

      public static Color GREEN
    • LIGHTGRAY

      public static Color LIGHTGRAY
    • MAGENTA

      public static Color MAGENTA
    • ORANGE

      public static Color ORANGE
    • PINK

      public static Color PINK
    • RED

      public static Color RED
    • WHITE

      public static Color WHITE
    • YELLOW

      public static Color YELLOW
    • CLEAR

      public static Color CLEAR
    • LIGHTBLUE

      public static Color LIGHTBLUE
    • CLEARWHITE

      public static Color CLEARWHITE
    • CRIMSON

      public static Color CRIMSON
    • GRAY1

      public static Color GRAY1
    • GRAY2

      public static Color GRAY2
    • GRAY3

      public static Color GRAY3
    • GRAY4

      public static Color GRAY4
    • GRAY5

      public static Color GRAY5
    • GRAY6

      public static Color GRAY6
    • GRAY7

      public static Color GRAY7
    • GRAY8

      public static Color GRAY8
    • GRAY9

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

      public Color(String aHexStr)
      Creates a new color from the given hex string.
    • Color

      public Color(ColorSpace aCS, float[] comps, double alpha)
      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

      public Color brighter()
      Returns a color brighter than this color (blended with white).
    • darker

      public Color darker()
      Returns a color darker than this color (blended with black).
    • blend

      public Color blend(Color aColor, double aFraction)
      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 interface Paint
    • isOpaque

      public boolean isOpaque()
      Returns whether paint is opaque.
      Specified by:
      isOpaque in interface Paint
    • getColor

      public Color getColor()
      Returns the closest color approximation of this paint.
      Specified by:
      getColor in interface Paint
    • copyForColor

      public Paint copyForColor(Color aColor)
      Returns a copy of this paint modified for given color.
      Specified by:
      copyForColor in interface Paint
    • copyForAlpha

      public Color copyForAlpha(double anAlpha)
      Returns a copy of this paint modified for given color.
    • copyForRect

      public Color copyForRect(Rect aRect)
      Returns an absolute paint for given bounds of primitive to be filled.
      Specified by:
      copyForRect in interface Paint
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Standard Hashcode implementation.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of this color.
      Overrides:
      toString in class Object
    • toHexString

      public String toHexString()
      Returns a hex string representation of this color.
    • getComponents

      public 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. If compArray is null, an array with length equal to number of components in cspace plus one is created.
    • getColorComponents

      public 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. If compArray is null, an array with length equal to the number of components in cspace is created.
    • getColorSpace

      public ColorSpace getColorSpace()
      Returns the ColorSpace of this Color.
    • getComponents

      public float[] getComponents()
    • get

      public static Color get(Object anObj)
      Returns a color value for a given object.
    • getRandom

      public static Color getRandom()
      Returns a random color.
    • toXML

      public XMLElement toXML(XMLArchiver anArchiver)
      XML archival.
      Specified by:
      toXML in interface XMLArchiver.Archivable
    • fromXML

      public Object fromXML(XMLArchiver anArchiver, XMLElement anElement)
      XML unarchival.
      Specified by:
      fromXML in interface XMLArchiver.Archivable