Class ModelColor


  • public class ModelColor
    extends java.lang.Object
    A RYB Color model $Revision: 2254 $
    • Constructor Summary

      Constructors 
      Constructor Description
      ModelColor​(double H, double S, double V)  
      ModelColor​(int R, int G, int B)
      Create a new ModelColor
      ModelColor​(int R, int G, int B, int H)
      Create a new ModelColor
      ModelColor​(ModelColor c)
      Creates a copy of an ModelColor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void calculateHSVfromRGB()  
      private void calculateRGBfromHSV()  
      private void checkRange()
      Check that the RGB values are in range
      static java.lang.String col2Gray​(double r, double g, double b)
      Get a grayscale hex value for an rgb color
      static java.lang.String dec2hex​(int n)
      Convert a decimal rgb value to a hexadecimal value
      static ModelColor[][] getBaseColors()  
      int getBlue()
      Get the blue value
      double getBrightness()
      Get the brightness value
      int getGreen()
      Get the green value
      double getH()
      Get the hue value
      int getHue()
      Get the hue value
      int getRed()
      Get the red value
      private void getRgbMinMaxValues()
      Get the minimum and maximum of the RGB values.
      double getSaturation()
      Get the saturation value
      static int hex2dec​(java.lang.String n)
      Convert a hexadecimal rgb value to a decimal value
      private static void initColorWheel()  
      void rotate​(int angle)
      Rotate this color by a specified amount
      void setHSV​(double _h, double _s, double _v)
      Set the color to a HSV value
      void setRGB​(int R, int G, int B)
      Set an RGB color
      void setRGB​(int r, int g, int b, int h)
      Set an RGB color
      void setWebSnap​(boolean snapTo)
      Set the snap to web colors setting
      static java.lang.String toHexString​(int value)
      Get a two letter hex string for the decimal value in the range 0-255
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • webSnap

        protected boolean webSnap
      • baseColors

        private static ModelColor[][] baseColors
      • R

        protected int R
      • G

        protected int G
      • B

        protected int B
      • H

        protected double H
      • S

        protected double S
      • V

        protected double V
      • rgbMinValue

        protected double rgbMinValue
      • rgbMaxValue

        protected double rgbMaxValue
      • SATURATION_BANDS

        public static double[] SATURATION_BANDS
      • BRIGHTNESS_BANDS

        public static double[] BRIGHTNESS_BANDS
    • Constructor Detail

      • ModelColor

        public ModelColor​(int R,
                          int G,
                          int B)
        Create a new ModelColor
        Parameters:
        R - the red value in the range 0-255
        G - the green value in the range 0-255
        B - the blue value in the range 0-255
      • ModelColor

        public ModelColor​(double H,
                          double S,
                          double V)
      • ModelColor

        public ModelColor​(int R,
                          int G,
                          int B,
                          int H)
        Create a new ModelColor
        Parameters:
        R - the red value in the range 0-255
        G - the green value in the range 0-255
        B - the blue value in the range 0-255
        H - the hue value in the range 0-255
      • ModelColor

        public ModelColor​(ModelColor c)
        Creates a copy of an ModelColor
        Parameters:
        c - the ModelColor to copy
    • Method Detail

      • getRed

        public int getRed()
        Get the red value
        Returns:
        the red value in the range 0-255
      • getGreen

        public int getGreen()
        Get the green value
        Returns:
        the green value in the range 0-255
      • getBlue

        public int getBlue()
        Get the blue value
        Returns:
        the blue value in the range 0-255
      • getHue

        public int getHue()
        Get the hue value
        Returns:
        the hue value in the range 0-255
      • getH

        public double getH()
        Get the hue value
        Returns:
        the hue value in the range 0-255
      • getSaturation

        public double getSaturation()
        Get the saturation value
        Returns:
        the saturation value in the range 0.0-1.0
      • getBrightness

        public double getBrightness()
        Get the brightness value
        Returns:
        the brightness value in the range 0.0-1.0
      • setRGB

        public void setRGB​(int R,
                           int G,
                           int B)
        Set an RGB color
        Parameters:
        R - the red value in the range 0-255
        G - the green value in the range 0-255
        B - the blue value in the range 0-255
      • setRGB

        public void setRGB​(int r,
                           int g,
                           int b,
                           int h)
        Set an RGB color
        Parameters:
        r - the red value in the range 0-255
        g - the green value in the range 0-255
        b - the blue value in the range 0-255
        h - the hue value in the range 0-255
      • setHSV

        public void setHSV​(double _h,
                           double _s,
                           double _v)
        Set the color to a HSV value
        Parameters:
        _h - the hue
        _s - the saturation
        _v - the value
      • checkRange

        private void checkRange()
        Check that the RGB values are in range
      • getRgbMinMaxValues

        private void getRgbMinMaxValues()
        Get the minimum and maximum of the RGB values.
      • calculateHSVfromRGB

        private void calculateHSVfromRGB()
      • calculateRGBfromHSV

        private void calculateRGBfromHSV()
      • rotate

        public void rotate​(int angle)
        Rotate this color by a specified amount
        Parameters:
        angle - the angle by which to move this color (hue)
      • setWebSnap

        public void setWebSnap​(boolean snapTo)
        Set the snap to web colors setting
        Parameters:
        snapTo - true to snap to web colors
      • dec2hex

        public static java.lang.String dec2hex​(int n)
        Convert a decimal rgb value to a hexadecimal value
        Parameters:
        n - the decimal value
        Returns:
        the hex value
      • hex2dec

        public static int hex2dec​(java.lang.String n)
        Convert a hexadecimal rgb value to a decimal value
        Parameters:
        n - the hex value
        Returns:
        the decimal value
      • toHexString

        public static java.lang.String toHexString​(int value)
        Get a two letter hex string for the decimal value in the range 0-255
      • col2Gray

        public static java.lang.String col2Gray​(double r,
                                                double g,
                                                double b)
        Get a grayscale hex value for an rgb color
        Parameters:
        r - the red value
        g - the green value
        b - the blue value
        Returns:
        the hex value
      • getBaseColors

        public static ModelColor[][] getBaseColors()
      • initColorWheel

        private static void initColorWheel()