Class TonalPalette

  • All Implemented Interfaces:
    BaseTonalPalette

    public final class TonalPalette
    extends java.lang.Object
    implements BaseTonalPalette
    A convenience class for retrieving colors that are constant in hue and chroma, but vary in tone.

    TonalPalette is intended for use in a single thread due to its stateful caching.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  TonalPalette.KeyColor
      Key color is a color that represents the hue and chroma of a tonal palette.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.Integer,​java.lang.Integer> cache  
      private double chroma  
      private double hue  
      private Hct keyColor  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TonalPalette​(double hue, double chroma, Hct keyColor)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int averageArgb​(int argb1, int argb2)  
      static TonalPalette fromHct​(Hct hct)
      Create tones using a HCT color.
      static TonalPalette fromHueAndChroma​(double hue, double chroma)
      Create tones from a defined HCT hue and chroma.
      static TonalPalette fromInt​(int argb)
      Create tones using the HCT hue and chroma from a color.
      double getChroma()
      The chroma of the Tonal Palette, in HCT.
      Hct getHct​(double tone)
      Given a tone, use hue and chroma of palette to create a color, and return it as HCT.
      double getHue()
      The hue of the Tonal Palette, in HCT.
      Hct getKeyColor()
      The key color is the first tone, starting from T50, that matches the palette's chroma.
      int tone​(int tone)
      Create an ARGB color with HCT hue and chroma of this Tones instance, and the provided HCT tone.
      • Methods inherited from class java.lang.Object

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

      • cache

        private final java.util.Map<java.lang.Integer,​java.lang.Integer> cache
      • keyColor

        private final Hct keyColor
      • hue

        private final double hue
      • chroma

        private final double chroma
    • Constructor Detail

      • TonalPalette

        private TonalPalette​(double hue,
                             double chroma,
                             Hct keyColor)
    • Method Detail

      • fromInt

        public static TonalPalette fromInt​(int argb)
        Create tones using the HCT hue and chroma from a color.
        Parameters:
        argb - ARGB representation of a color
        Returns:
        Tones matching that color's hue and chroma.
      • fromHct

        public static TonalPalette fromHct​(Hct hct)
        Create tones using a HCT color.
        Parameters:
        hct - HCT representation of a color.
        Returns:
        Tones matching that color's hue and chroma.
      • fromHueAndChroma

        public static TonalPalette fromHueAndChroma​(double hue,
                                                    double chroma)
        Create tones from a defined HCT hue and chroma.
        Parameters:
        hue - HCT hue
        chroma - HCT chroma
        Returns:
        Tones matching hue and chroma.
      • tone

        public int tone​(int tone)
        Create an ARGB color with HCT hue and chroma of this Tones instance, and the provided HCT tone.
        Specified by:
        tone in interface BaseTonalPalette
        Parameters:
        tone - HCT tone, measured from 0 to 100.
        Returns:
        ARGB representation of a color with that tone.
      • averageArgb

        private int averageArgb​(int argb1,
                                int argb2)
      • getHct

        public Hct getHct​(double tone)
        Given a tone, use hue and chroma of palette to create a color, and return it as HCT.
        Specified by:
        getHct in interface BaseTonalPalette
      • getChroma

        public double getChroma()
        The chroma of the Tonal Palette, in HCT. Ranges from 0 to ~130 (for sRGB gamut).
      • getHue

        public double getHue()
        The hue of the Tonal Palette, in HCT. Ranges from 0 to 360.
      • getKeyColor

        public Hct getKeyColor()
        The key color is the first tone, starting from T50, that matches the palette's chroma.