Class SquidColorCenter

java.lang.Object
squidpony.squidgrid.gui.gdx.SquidColorCenter
All Implemented Interfaces:
IColorCenter<com.badlogic.gdx.graphics.Color>

public class SquidColorCenter
extends Object
implements IColorCenter<com.badlogic.gdx.graphics.Color>
A concrete implementation of IColorCenter for libgdx's Color. Supports filtering any colors that this creates using an IFilter, such as one from Filters. This class largely supersedes the earlier SColorFactory class, and supports similar operations while also allowing filters to modify the returned colors. SColorFactory has been removed, so code transitioning to SquidColorCenter may need to change blend() to lerp(Color, Color, double), and setFloor() to setGranularity(int) (with different behavior).
Author:
smelC, Tommy Ettinger
See Also:
Another way to obtain colors by using pre-allocated (and named) instances.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface squidpony.IColorCenter

    IColorCenter.Skeleton<T extends Object>
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected com.badlogic.gdx.utils.IntMap<com.badlogic.gdx.graphics.Color> cache  
    IFilter<com.badlogic.gdx.graphics.Color> filter  
  • Constructor Summary

    Constructors 
    Constructor Description
    SquidColorCenter()
    A fresh filter-less color center.
    SquidColorCenter​(IFilter<com.badlogic.gdx.graphics.Color> filterEffect)
    A fresh filtered color center.
  • Method Summary

    Modifier and Type Method Description
    int cacheSize()
    The actual cache is not public, but there are cases where you may want to know how many different colors are actually used in a frame or a section of the game.
    void clearCache()
    It clears the cache.
    void copyCache​(SquidColorCenter other)
    You may want to copy colors between IColorCenter instances that have different create() methods -- and as such, will have different values for the same keys in the cache.
    com.badlogic.gdx.graphics.Color desaturate​(com.badlogic.gdx.graphics.Color color, double degree)
    Brings a color closer to grayscale by the specified degree and returns the new color (desaturated somewhat).
    com.badlogic.gdx.graphics.Color desaturate​(com.badlogic.gdx.graphics.Color color, float degree)
    Brings a color closer to grayscale by the specified degree and returns the new color (desaturated somewhat).
    com.badlogic.gdx.graphics.Color desaturated​(com.badlogic.gdx.graphics.Color color)
    Gets a fully-desaturated version of the given color (keeping its brightness, but making it grayscale).
    com.badlogic.gdx.graphics.Color dim​(com.badlogic.gdx.graphics.Color color)
    Darkens a color slightly and returns the new color (10% mix with black).
    com.badlogic.gdx.graphics.Color dim​(com.badlogic.gdx.graphics.Color color, double degree)
    Darkens a color by the specified degree and returns the new color (mixed with black).
    com.badlogic.gdx.graphics.Color dim​(com.badlogic.gdx.graphics.Color color, float degree)
    Darkens a color by the specified degree and returns the new color (mixed with black).
    com.badlogic.gdx.graphics.Color dimmer​(com.badlogic.gdx.graphics.Color color)
    Darkens a color significantly and returns the new color (30% mix with black).
    com.badlogic.gdx.graphics.Color dimmest​(com.badlogic.gdx.graphics.Color color)
    Darkens a color massively and returns the new color (70% mix with black).
    static int encode​(com.badlogic.gdx.graphics.Color color)  
    com.badlogic.gdx.graphics.Color filter​(com.badlogic.gdx.graphics.Color c)  
    IColoredString<com.badlogic.gdx.graphics.Color> filter​(IColoredString<com.badlogic.gdx.graphics.Color> ics)  
    com.badlogic.gdx.graphics.Color get​(float r, float g, float b, float a)  
    com.badlogic.gdx.graphics.Color get​(int red, int green, int blue)  
    com.badlogic.gdx.graphics.Color get​(int red, int green, int blue, int opacity)  
    com.badlogic.gdx.graphics.Color get​(long c)  
    int getAlpha​(com.badlogic.gdx.graphics.Color c)  
    com.badlogic.gdx.graphics.Color getBlack()  
    int getBlue​(com.badlogic.gdx.graphics.Color c)  
    int getGranularity()
    Gets the granularity, which is how different requested colors need to be to make a new color; can be from 0 to 6.
    int getGreen​(com.badlogic.gdx.graphics.Color c)  
    com.badlogic.gdx.graphics.Color getHSV​(float hue, float saturation, float value)  
    com.badlogic.gdx.graphics.Color getHSV​(float hue, float saturation, float value, float opacity)  
    float getHue​(float r, float g, float b)  
    float getHue​(com.badlogic.gdx.graphics.Color c)  
    com.badlogic.gdx.graphics.Color getRandom​(IRNG rng, int opacity)  
    int getRed​(com.badlogic.gdx.graphics.Color c)  
    float getSaturation​(float r, float g, float b)  
    float getSaturation​(com.badlogic.gdx.graphics.Color c)  
    com.badlogic.gdx.graphics.Color getTransparent()  
    float getValue​(float r, float g, float b)  
    float getValue​(com.badlogic.gdx.graphics.Color c)  
    com.badlogic.gdx.graphics.Color getWhite()  
    ArrayList<com.badlogic.gdx.graphics.Color> gradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor)
    Finds a 16-step gradient going from fromColor to toColor, both included in the gradient.
    ArrayList<com.badlogic.gdx.graphics.Color> gradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor, int steps)
    Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient.
    ArrayList<com.badlogic.gdx.graphics.Color> gradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor, int steps, com.badlogic.gdx.math.Interpolation interpolation)
    Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient.
    com.badlogic.gdx.graphics.Color greify​(com.badlogic.gdx.graphics.Color color, boolean doAlpha)
    Gets a copy of t and modifies it to make a shade of gray with the same brightness.
    com.badlogic.gdx.graphics.Color invert​(com.badlogic.gdx.graphics.Color start)  
    com.badlogic.gdx.graphics.Color lerp​(com.badlogic.gdx.graphics.Color start, com.badlogic.gdx.graphics.Color end, double change)
    Gets the linear interpolation from Color start to Color end, changing by the fraction given by change.
    com.badlogic.gdx.graphics.Color lerp​(com.badlogic.gdx.graphics.Color start, com.badlogic.gdx.graphics.Color end, float change)
    Gets the linear interpolation from Color start to Color end, changing by the fraction given by change.
    com.badlogic.gdx.graphics.Color light​(com.badlogic.gdx.graphics.Color color)
    Lightens a color slightly and returns the new color (10% mix with white).
    com.badlogic.gdx.graphics.Color light​(com.badlogic.gdx.graphics.Color color, double degree)
    Lightens a color by degree and returns the new color (mixed with white).
    com.badlogic.gdx.graphics.Color light​(com.badlogic.gdx.graphics.Color color, float degree)
    Lightens a color by degree and returns the new color (mixed with white).
    com.badlogic.gdx.graphics.Color lighter​(com.badlogic.gdx.graphics.Color color)
    Lightens a color significantly and returns the new color (30% mix with white).
    com.badlogic.gdx.graphics.Color lightest​(com.badlogic.gdx.graphics.Color color)
    Lightens a color massively and returns the new color (70% mix with white).
    com.badlogic.gdx.graphics.Color lightWith​(com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.graphics.Color light)
    Gets a modified copy of color as if it is lit with a colored light source.
    ArrayList<com.badlogic.gdx.graphics.Color> loopingGradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color midColor, int steps)
    Finds a gradient with the specified number of steps going from fromColor to midColor, then midColor to (possibly) fromColor, with both included in the gradient but fromColor only repeated at the end if the number of steps is odd.
    ArrayList<com.badlogic.gdx.graphics.Color> loopingGradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color midColor, int steps, com.badlogic.gdx.math.Interpolation interpolation)
    Finds a gradient with the specified number of steps going from fromColor to midColor, then midColor to (possibly) fromColor, with both included in the gradient but fromColor only repeated at the end if the number of steps is odd.
    ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(double saturation, double value, double opacity, int steps)
    Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again.
    ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(double saturation, double value, int steps)
    Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again.
    ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(float saturation, float value, float opacity, int steps)
    Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again.
    ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(float saturation, float value, int steps)
    Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again.
    ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(int steps)
    Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again.
    com.badlogic.gdx.graphics.Color random()
    Gets a fully random color that is only required to be opaque.
    com.badlogic.gdx.graphics.Color randomBlend​(com.badlogic.gdx.graphics.Color a, com.badlogic.gdx.graphics.Color b)
    Blends the colors A and B by a random degree.
    com.badlogic.gdx.graphics.Color randomize​(com.badlogic.gdx.graphics.Color color)
    Blends a color with a random (opaque) color by a factor of 10% random.
    com.badlogic.gdx.graphics.Color randomizeMore​(com.badlogic.gdx.graphics.Color color)
    Blends a color with a random (opaque) color by a factor of 30% random.
    com.badlogic.gdx.graphics.Color randomizeMost​(com.badlogic.gdx.graphics.Color color)
    Blends a color with a random (opaque) color by a factor of 70% random.
    com.badlogic.gdx.graphics.Color saturate​(com.badlogic.gdx.graphics.Color color, double degree)
    Saturates color (makes it closer to a vivid color like red or green and less gray) by the specified degree and returns the new color (saturated somewhat).
    com.badlogic.gdx.graphics.Color saturate​(com.badlogic.gdx.graphics.Color color, float degree)
    Saturates color (makes it closer to a vivid color like red or green and less gray) by the specified degree and returns the new color (saturated somewhat).
    com.badlogic.gdx.graphics.Color saturated​(com.badlogic.gdx.graphics.Color color)
    Fully saturates color (makes it a vivid color like red or green and less gray) and returns the modified copy.
    void setGranularity​(int granularity)
    Sets the granularity, which is how different requested colors must be to make a new color; from 0 to at most 6.
    String toString()  
    ArrayList<com.badlogic.gdx.graphics.Color> zigzagGradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor, int steps)
    Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • filter

      public IFilter<com.badlogic.gdx.graphics.Color> filter
    • cache

      protected com.badlogic.gdx.utils.IntMap<com.badlogic.gdx.graphics.Color> cache
  • Constructor Details

  • Method Details

    • getGranularity

      public int getGranularity()
      Gets the granularity, which is how different requested colors need to be to make a new color; can be from 0 to 6. If this is 0, all requested colors will be looked up (using a cached version if the exact request had been made before), but if this is greater than 0, then exponentially less colors will be used, using the cache for twice as many requests at granularity 1 (2 raised to the granularity), four times as many at granularity 2, and so on. If no granularity was set, the default is 1.
      Returns:
      the current granularity, as an int
    • setGranularity

      public void setGranularity​(int granularity)
      Sets the granularity, which is how different requested colors must be to make a new color; from 0 to at most 6. If this is 0, all requested colors will be looked up (using a cached version if the exact request had been made before), but if this is greater than 0, then exponentially less colors will be used, using the cache for twice as many requests at granularity 1 (2 raised to the granularity), four times as many at granularity 2, and so on. If no granularity was set, the default is 1.
      Parameters:
      granularity - the granularity to use; will be clamped between 0 and 6
    • get

      public com.badlogic.gdx.graphics.Color get​(int red, int green, int blue, int opacity)
      Specified by:
      get in interface IColorCenter<com.badlogic.gdx.graphics.Color>
    • get

      public com.badlogic.gdx.graphics.Color get​(int red, int green, int blue)
      Specified by:
      get in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      red - The red component. For screen colors, in-between 0 (inclusive) and 256 (exclusive).
      green - The green component. For screen colors, in-between 0 (inclusive) and 256 (exclusive).
      blue - The blue component. For screen colors, in-between 0 (inclusive) and 256 (exclusive).
      Returns:
      An opaque color.
    • getHSV

      public com.badlogic.gdx.graphics.Color getHSV​(float hue, float saturation, float value, float opacity)
      Specified by:
      getHSV in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      hue - The hue of the desired color from 0.0 (red, inclusive) towards orange, then yellow, and eventually to purple before looping back to almost the same red (1.0, exclusive). Values outside this range should be treated as wrapping around, so 1.1f and -0.9f would be the same as 0.1f .
      saturation - the saturation of the color from 0.0 (a grayscale color; inclusive) to 1.0 (a bright color, inclusive)
      value - the value (essentially lightness) of the color from 0.0 (black, inclusive) to 1.0 (very bright, inclusive).
      opacity - the alpha component as a float; 0.0f is clear, 1.0f is opaque.
      Returns:
      a possibly transparent color
    • getHSV

      public com.badlogic.gdx.graphics.Color getHSV​(float hue, float saturation, float value)
      Specified by:
      getHSV in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      hue - The hue of the desired color from 0.0 (red, inclusive) towards orange, then yellow, and eventually to purple before looping back to almost the same red (1.0, exclusive)
      saturation - the saturation of the color from 0.0 (a grayscale color; inclusive) to 1.0 (a bright color, exclusive)
      value - the value (essentially lightness) of the color from 0.0 (black, inclusive) to 1.0 (very bright, inclusive).
      Returns:
      an opaque color
    • getWhite

      public com.badlogic.gdx.graphics.Color getWhite()
      Specified by:
      getWhite in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Returns:
      Opaque white.
    • getBlack

      public com.badlogic.gdx.graphics.Color getBlack()
      Specified by:
      getBlack in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Returns:
      Opaque black.
    • getTransparent

      public com.badlogic.gdx.graphics.Color getTransparent()
      Specified by:
      getTransparent in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Returns:
      The fully transparent color.
    • getRandom

      public com.badlogic.gdx.graphics.Color getRandom​(IRNG rng, int opacity)
      Specified by:
      getRandom in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      rng - any IRNG from SquidLib, such as an RNG, StatefulRNG, or GWTRNG.
      opacity - The alpha component. In-between 0 (inclusive) and 256 (exclusive). Larger values mean more opacity; 0 is clear.
      Returns:
      A random color, except for the alpha component.
    • filter

      public com.badlogic.gdx.graphics.Color filter​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      filter in interface IColorCenter<com.badlogic.gdx.graphics.Color>
    • filter

      public IColoredString<com.badlogic.gdx.graphics.Color> filter​(IColoredString<com.badlogic.gdx.graphics.Color> ics)
      Specified by:
      filter in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      ics - an IColoredString, often produced by GDXMarkup.colorString(CharSequence).
      Returns:
      ics filtered according to filter(Color). May be ics itself if unchanged.
    • greify

      public com.badlogic.gdx.graphics.Color greify​(com.badlogic.gdx.graphics.Color color, boolean doAlpha)
      Gets a copy of t and modifies it to make a shade of gray with the same brightness. The doAlpha parameter causes the alpha to be considered in the calculation of brightness and also changes the returned alpha of the color, so translucent colors are considered darker and fully clear ones are black (and still fully clear).
      This uses a perceptual calculation of brightness that matches the luma calculation used in the YCbCr color space. It does not necessarily match other brightness calculations, such as value as used in HSV.
      Not related to reified types or any usage of "reify."
      Specified by:
      greify in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      color - a T to copy; only the copy will be modified
      doAlpha - Whether to include (and hereby change) the alpha component; if false alpha is kept as-is
      Returns:
      A monochromatic variation of t.
    • get

      public com.badlogic.gdx.graphics.Color get​(long c)
    • get

      public com.badlogic.gdx.graphics.Color get​(float r, float g, float b, float a)
    • lerp

      public com.badlogic.gdx.graphics.Color lerp​(com.badlogic.gdx.graphics.Color start, com.badlogic.gdx.graphics.Color end, float change)
      Gets the linear interpolation from Color start to Color end, changing by the fraction given by change.
      Specified by:
      lerp in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      start - the initial Color
      end - the "target" color
      change - the degree to change closer to end; a change of 0.0f produces start, 1.0f produces end
      Returns:
      a new Color
    • lerp

      public com.badlogic.gdx.graphics.Color lerp​(com.badlogic.gdx.graphics.Color start, com.badlogic.gdx.graphics.Color end, double change)
      Gets the linear interpolation from Color start to Color end, changing by the fraction given by change.
      Parameters:
      start - the initial Color
      end - the "target" color
      change - the degree to change closer to end; a change of 0.0 produces start, 1.0 produces end
      Returns:
      a new Color
    • getRed

      public int getRed​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      getRed in interface IColorCenter<com.badlogic.gdx.graphics.Color>
    • getGreen

      public int getGreen​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      getGreen in interface IColorCenter<com.badlogic.gdx.graphics.Color>
    • getBlue

      public int getBlue​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      getBlue in interface IColorCenter<com.badlogic.gdx.graphics.Color>
    • getAlpha

      public int getAlpha​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      getAlpha in interface IColorCenter<com.badlogic.gdx.graphics.Color>
    • getHue

      public float getHue​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      getHue in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      c - a concrete color
      Returns:
      The hue of the color from 0.0 (red, inclusive) towards orange, then yellow, and eventually to purple before looping back to almost the same red (1.0, exclusive)
    • getSaturation

      public float getSaturation​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      getSaturation in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      c - a concrete color
      Returns:
      the saturation of the color from 0.0 (a grayscale color; inclusive) to 1.0 (a bright color, exclusive)
    • getSaturation

      public float getSaturation​(float r, float g, float b)
      Parameters:
      r - the red component in 0.0 to 1.0 range, typically
      g - the green component in 0.0 to 1.0 range, typically
      b - the blue component in 0.0 to 1.0 range, typically
      Returns:
      the saturation of the color from 0.0 (a grayscale color; inclusive) to 1.0 (a bright color, exclusive)
    • getValue

      public float getValue​(float r, float g, float b)
      Parameters:
      r - the red component in 0.0 to 1.0 range, typically
      g - the green component in 0.0 to 1.0 range, typically
      b - the blue component in 0.0 to 1.0 range, typically
      Returns:
      the value (essentially lightness) of the color from 0.0 (black, inclusive) to 1.0 (very bright, inclusive).
    • getHue

      public float getHue​(float r, float g, float b)
      Parameters:
      r - the red component in 0.0 to 1.0 range, typically
      g - the green component in 0.0 to 1.0 range, typically
      b - the blue component in 0.0 to 1.0 range, typically
      Returns:
      The hue of the color from 0.0 (red, inclusive) towards orange, then yellow, and eventually to purple before looping back to almost the same red (1.0, exclusive)
    • getValue

      public float getValue​(com.badlogic.gdx.graphics.Color c)
      Specified by:
      getValue in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      c - a concrete color
      Returns:
      the value (essentially lightness) of the color from 0.0 (black, inclusive) to 1.0 (very bright, inclusive).
    • encode

      public static int encode​(com.badlogic.gdx.graphics.Color color)
    • lightWith

      public com.badlogic.gdx.graphics.Color lightWith​(com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.graphics.Color light)
      Gets a modified copy of color as if it is lit with a colored light source.
      Parameters:
      color - the color to shine the light on
      light - the color of the light source
      Returns:
      a copy of the Color color that factors in the lighting of the Color light.
    • light

      public com.badlogic.gdx.graphics.Color light​(com.badlogic.gdx.graphics.Color color, float degree)
      Lightens a color by degree and returns the new color (mixed with white).
      Parameters:
      color - the color to lighten
      degree - a float between 0.0f and 1.0f; more makes it lighter
      Returns:
      the lightened (and if a filter is used, also filtered) new color
    • light

      public com.badlogic.gdx.graphics.Color light​(com.badlogic.gdx.graphics.Color color, double degree)
      Lightens a color by degree and returns the new color (mixed with white).
      Parameters:
      color - the color to lighten
      degree - a double between 0.0 and 1.0; more makes it lighter
      Returns:
      the lightened (and if a filter is used, also filtered) new color
    • light

      public com.badlogic.gdx.graphics.Color light​(com.badlogic.gdx.graphics.Color color)
      Lightens a color slightly and returns the new color (10% mix with white).
      Parameters:
      color - the color to lighten
      Returns:
      the lightened (and if a filter is used, also filtered) new color
    • lighter

      public com.badlogic.gdx.graphics.Color lighter​(com.badlogic.gdx.graphics.Color color)
      Lightens a color significantly and returns the new color (30% mix with white).
      Parameters:
      color - the color to lighten
      Returns:
      the lightened (and if a filter is used, also filtered) new color
    • lightest

      public com.badlogic.gdx.graphics.Color lightest​(com.badlogic.gdx.graphics.Color color)
      Lightens a color massively and returns the new color (70% mix with white).
      Parameters:
      color - the color to lighten
      Returns:
      the lightened (and if a filter is used, also filtered) new color
    • dim

      public com.badlogic.gdx.graphics.Color dim​(com.badlogic.gdx.graphics.Color color, float degree)
      Darkens a color by the specified degree and returns the new color (mixed with black).
      Parameters:
      color - the color to darken
      degree - a float between 0.0f and 1.0f; more makes it darker
      Returns:
      the darkened (and if a filter is used, also filtered) new color
    • dim

      public com.badlogic.gdx.graphics.Color dim​(com.badlogic.gdx.graphics.Color color, double degree)
      Darkens a color by the specified degree and returns the new color (mixed with black).
      Parameters:
      color - the color to darken
      degree - a double between 0.0 and 1.0; more makes it darker
      Returns:
      the darkened (and if a filter is used, also filtered) new color
    • dim

      public com.badlogic.gdx.graphics.Color dim​(com.badlogic.gdx.graphics.Color color)
      Darkens a color slightly and returns the new color (10% mix with black).
      Parameters:
      color - the color to darken
      Returns:
      the darkened (and if a filter is used, also filtered) new color
    • dimmer

      public com.badlogic.gdx.graphics.Color dimmer​(com.badlogic.gdx.graphics.Color color)
      Darkens a color significantly and returns the new color (30% mix with black).
      Parameters:
      color - the color to darken
      Returns:
      the darkened (and if a filter is used, also filtered) new color
    • dimmest

      public com.badlogic.gdx.graphics.Color dimmest​(com.badlogic.gdx.graphics.Color color)
      Darkens a color massively and returns the new color (70% mix with black).
      Parameters:
      color - the color to darken
      Returns:
      the darkened (and if a filter is used, also filtered) new color
    • desaturated

      public com.badlogic.gdx.graphics.Color desaturated​(com.badlogic.gdx.graphics.Color color)
      Gets a fully-desaturated version of the given color (keeping its brightness, but making it grayscale).
      Specified by:
      desaturated in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      color - the color to desaturate (will not be modified)
      Returns:
      the grayscale version of color
    • desaturate

      public com.badlogic.gdx.graphics.Color desaturate​(com.badlogic.gdx.graphics.Color color, float degree)
      Brings a color closer to grayscale by the specified degree and returns the new color (desaturated somewhat).
      Specified by:
      desaturate in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      color - the color to desaturate
      degree - a float between 0.0f and 1.0f; more makes it less colorful
      Returns:
      the desaturated (and if a filter is used, also filtered) new color
    • desaturate

      public com.badlogic.gdx.graphics.Color desaturate​(com.badlogic.gdx.graphics.Color color, double degree)
      Brings a color closer to grayscale by the specified degree and returns the new color (desaturated somewhat).
      Parameters:
      color - the color to desaturate
      degree - a double between 0.0 and 1.0; more makes it less colorful
      Returns:
      the desaturated (and if a filter is used, also filtered) new color
    • saturated

      public com.badlogic.gdx.graphics.Color saturated​(com.badlogic.gdx.graphics.Color color)
      Fully saturates color (makes it a vivid color like red or green and less gray) and returns the modified copy. Leaves alpha unchanged.
      Specified by:
      saturated in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      color - the color T to saturate (will not be modified)
      Returns:
      the saturated version of color
    • saturate

      public com.badlogic.gdx.graphics.Color saturate​(com.badlogic.gdx.graphics.Color color, float degree)
      Saturates color (makes it closer to a vivid color like red or green and less gray) by the specified degree and returns the new color (saturated somewhat). If this is called on a color that is very close to gray, this is likely to produce a red hue by default (if there's no hue to make vivid, it needs to choose something).
      Specified by:
      saturate in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      color - the color to saturate
      degree - a float between 0.0f and 1.0f; more makes it more colorful
      Returns:
      the saturated (and if a filter is used, also filtered) new color
    • saturate

      public com.badlogic.gdx.graphics.Color saturate​(com.badlogic.gdx.graphics.Color color, double degree)
      Saturates color (makes it closer to a vivid color like red or green and less gray) by the specified degree and returns the new color (saturated somewhat). If this is called on a color that is very close to gray, this is likely to produce a red hue by default (if there's no hue to make vivid, it needs to choose something).
      Parameters:
      color - the color to saturate
      degree - a double between 0.0 and 1.0; more makes it more colorful
      Returns:
      the saturated (and if a filter is used, also filtered) new color
    • random

      public com.badlogic.gdx.graphics.Color random()
      Gets a fully random color that is only required to be opaque.
      Returns:
      a random Color
    • randomize

      public com.badlogic.gdx.graphics.Color randomize​(com.badlogic.gdx.graphics.Color color)
      Blends a color with a random (opaque) color by a factor of 10% random.
      Parameters:
      color - the color to randomize
      Returns:
      the randomized (and if a filter is used, also filtered) new color
    • randomizeMore

      public com.badlogic.gdx.graphics.Color randomizeMore​(com.badlogic.gdx.graphics.Color color)
      Blends a color with a random (opaque) color by a factor of 30% random.
      Parameters:
      color - the color to randomize
      Returns:
      the randomized (and if a filter is used, also filtered) new color
    • randomizeMost

      public com.badlogic.gdx.graphics.Color randomizeMost​(com.badlogic.gdx.graphics.Color color)
      Blends a color with a random (opaque) color by a factor of 70% random.
      Parameters:
      color - the color to randomize
      Returns:
      the randomized (and if a filter is used, also filtered) new color
    • randomBlend

      public com.badlogic.gdx.graphics.Color randomBlend​(com.badlogic.gdx.graphics.Color a, com.badlogic.gdx.graphics.Color b)
      Blends the colors A and B by a random degree.
      Parameters:
      a - a color to mix in
      b - another color to mix in
      Returns:
      a random blend of a and b.
    • invert

      public com.badlogic.gdx.graphics.Color invert​(com.badlogic.gdx.graphics.Color start)
    • gradient

      public ArrayList<com.badlogic.gdx.graphics.Color> gradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor)
      Finds a 16-step gradient going from fromColor to toColor, both included in the gradient.
      Specified by:
      gradient in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      fromColor - the color to start with, included in the gradient
      toColor - the color to end on, included in the gradient
      Returns:
      a 16-element ArrayList composed of the blending steps from fromColor to toColor
    • gradient

      public ArrayList<com.badlogic.gdx.graphics.Color> gradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor, int steps)
      Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient.
      Specified by:
      gradient in interface IColorCenter<com.badlogic.gdx.graphics.Color>
      Parameters:
      fromColor - the color to start with, included in the gradient
      toColor - the color to end on, included in the gradient
      steps - the number of elements to use in the gradient
      Returns:
      an ArrayList composed of the blending steps from fromColor to toColor, with length equal to steps
    • loopingGradient

      public ArrayList<com.badlogic.gdx.graphics.Color> loopingGradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color midColor, int steps)
      Finds a gradient with the specified number of steps going from fromColor to midColor, then midColor to (possibly) fromColor, with both included in the gradient but fromColor only repeated at the end if the number of steps is odd.
      Parameters:
      fromColor - the color to start with (and end with, if steps is an odd number), included in the gradient
      midColor - the color to use in the middle of the loop, included in the gradient
      steps - the number of elements to use in the gradient, will be at least 3
      Returns:
      an ArrayList composed of the blending steps from fromColor to midColor to fromColor again, with length equal to steps
    • gradient

      public ArrayList<com.badlogic.gdx.graphics.Color> gradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor, int steps, com.badlogic.gdx.math.Interpolation interpolation)
      Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient. The interpolation argument can be used to make the color stay close to fromColor and/or toColor longer than it would normally, or shorter if the middle colors are desirable.
      Parameters:
      fromColor - the color to start with, included in the gradient
      toColor - the color to end on, included in the gradient
      steps - the number of elements to use in the gradient
      interpolation - a libGDX Interpolation that defines how quickly the color changes during the transition
      Returns:
      an ArrayList composed of the blending steps from fromColor to toColor, with length equal to steps
    • loopingGradient

      public ArrayList<com.badlogic.gdx.graphics.Color> loopingGradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color midColor, int steps, com.badlogic.gdx.math.Interpolation interpolation)
      Finds a gradient with the specified number of steps going from fromColor to midColor, then midColor to (possibly) fromColor, with both included in the gradient but fromColor only repeated at the end if the number of steps is odd. The interpolation argument can be used to make the color linger for a while with colors close to fromColor or midColor, or to do the opposite and quickly change from one and spend more time in the middle.
      Parameters:
      fromColor - the color to start with (and end with, if steps is an odd number), included in the gradient
      midColor - the color to use in the middle of the loop, included in the gradient
      steps - the number of elements to use in the gradient, will be at least 3
      interpolation - a libGDX Interpolation that defines how quickly the color changes at the start and end of each transition, both from fromColor to midColor as well as back to fromColor
      Returns:
      an ArrayList composed of the blending steps from fromColor to midColor to fromColor again, with length equal to steps
    • rainbow

      public ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(int steps)
      Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again. If the given number of steps is less than 6 or so, you should expect to see only some of those colors; if steps is larger (36 may be reasonable for gradients), you are more likely to see colors that appear for shorter spans on the color wheel, like orange. Produces fully saturated and max-brightness colors on the rainbow, which is what many people expect for a rainbow.
      Parameters:
      steps - the number of different Color elements to generate in the returned ArrayList
      Returns:
      an ArrayList of Color where each element goes around the color wheel, starting at red, then orange, etc.
    • rainbow

      public ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(float saturation, float value, int steps)
      Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again. If the given number of steps is less than 6 or so, you should expect to see only some of those colors; if steps is larger (36 may be reasonable for gradients), you are more likely to see colors that appear for shorter spans on the color wheel, like orange. Uses the given saturation and value for all colors in the rainbow, and only changes hue.
      Parameters:
      saturation - the saturation of the rainbow's colors; 1.0 is boldest and 0.0 is grayscale
      value - the brightness of the rainbow's colors; 1.0 is brightest
      steps - the number of different Color elements to generate in the returned ArrayList
      Returns:
      an ArrayList of Color where each element goes around the color wheel, starting at red, then orange, etc.
    • rainbow

      public ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(float saturation, float value, float opacity, int steps)
      Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again. If the given number of steps is less than 6 or so, you should expect to see only some of those colors; if steps is larger (36 may be reasonable for gradients), you are more likely to see colors that appear for shorter spans on the color wheel, like orange. Uses the given saturation, value, and opacity for all colors in the rainbow, and only changes hue.
      Parameters:
      saturation - the saturation of the rainbow's colors; 1.0 is boldest and 0.0 is grayscale
      value - the brightness of the rainbow's colors; 1.0 is brightest
      opacity - the alpha value of all colors in the rainbow; 0.0 is fully transparent and 1.0 is opaque
      steps - the number of different Color elements to generate in the returned ArrayList
      Returns:
      an ArrayList of Color where each element goes around the color wheel, starting at red, then orange, etc.
    • rainbow

      public ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(double saturation, double value, int steps)
      Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again. If the given number of steps is less than 6 or so, you should expect to see only some of those colors; if steps is larger (36 may be reasonable for gradients), you are more likely to see colors that appear for shorter spans on the color wheel, like orange. Uses the given saturation and value for all colors in the rainbow, and only changes hue.
      Parameters:
      saturation - the saturation of the rainbow's colors; 1.0 is boldest and 0.0 is grayscale
      value - the brightness of the rainbow's colors; 1.0 is brightest
      steps - the number of different Color elements to generate in the returned ArrayList
      Returns:
      an ArrayList of Color where each element goes around the color wheel, starting at red, then orange, etc.
    • rainbow

      public ArrayList<com.badlogic.gdx.graphics.Color> rainbow​(double saturation, double value, double opacity, int steps)
      Generates a hue-shifted rainbow of colors, starting at red and going through orange, yellow, green, blue, and purple before getting close to red at the end again. If the given number of steps is less than 6 or so, you should expect to see only some of those colors; if steps is larger (36 may be reasonable for gradients), you are more likely to see colors that appear for shorter spans on the color wheel, like orange. Uses the given saturation, value, and opacity for all colors in the rainbow, and only changes hue.
      Parameters:
      saturation - the saturation of the rainbow's colors; 1.0 is boldest and 0.0 is grayscale
      value - the brightness of the rainbow's colors; 1.0 is brightest
      opacity - the alpha value of all colors in the rainbow; 0.0 is fully transparent and 1.0 is opaque
      steps - the number of different Color elements to generate in the returned ArrayList
      Returns:
      an ArrayList of Color where each element goes around the color wheel, starting at red, then orange, etc.
    • zigzagGradient

      public ArrayList<com.badlogic.gdx.graphics.Color> zigzagGradient​(com.badlogic.gdx.graphics.Color fromColor, com.badlogic.gdx.graphics.Color toColor, int steps)
      Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient. This does not typically take a direct path on its way between fromColor and toColor, and is useful to generate a wide variety of colors that can be confined to a rough amount of maximum difference by choosing values for fromColor and toColor that are more similar.
      Try using colors for fromColor and toColor that have different r, g, and b values, such as gray and white, then compare to colors that don't differ on, for example, r, such as bright red and pink. In the first case, red, green, blue, and many other colors will be generated if there are enough steps; in the second case, red will be at the same level in all generated colors (very high, so no pure blue or pure green, but purple and yellow are possible). This should help illustrate how this chooses how far to "zig-zag" off the straight-line path.
      Parameters:
      fromColor - the color to start with, included in the gradient
      toColor - the color to end on, included in the gradient
      steps - the number of elements to use in the gradient; ideally no greater than 345 to avoid duplicates
      Returns:
      an ArrayList composed of the zig-zag steps from fromColor to toColor, with length equal to steps
    • toString

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

      public void clearCache()
      It clears the cache. You may need to do this to limit the cache to the colors used in a specific section. This is also useful if a Filter changes what colors it should return on a frame-by-frame basis; in that case, you can call clearCache() at the start or end of a frame to ensure the next frame gets different colors.
    • cacheSize

      public int cacheSize()
      The actual cache is not public, but there are cases where you may want to know how many different colors are actually used in a frame or a section of the game. If the cache was emptied (which might be from calling clearCache()), some colors were requested, then this is called, the returned int should be the count of distinct colors this IColorCenter had created and cached; duplicates won't be counted twice.
      Returns:
    • copyCache

      public void copyCache​(SquidColorCenter other)
      You may want to copy colors between IColorCenter instances that have different create() methods -- and as such, will have different values for the same keys in the cache. This allows you to copy the cache from other into this Skeleton, but using this Skeleton's create() method.
      Parameters:
      other - another Skeleton of the same type that will have its cache copied into this Skeleton