Package squidpony.squidgrid.gui.gdx
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
-
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.
-
Field Details
-
Constructor Details
-
SquidColorCenter
public SquidColorCenter()A fresh filter-less color center. -
SquidColorCenter
A fresh filtered color center.- Parameters:
filterEffect
- The filter to use.
-
-
Method Details
-
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
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
- Specified by:
get
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
-
get
- Specified by:
get
in interfaceIColorCenter<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 interfaceIColorCenter<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
- Specified by:
getHSV
in interfaceIColorCenter<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
- Specified by:
getWhite
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Returns:
- Opaque white.
-
getBlack
- Specified by:
getBlack
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Returns:
- Opaque black.
-
getTransparent
- Specified by:
getTransparent
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Returns:
- The fully transparent color.
-
getRandom
- Specified by:
getRandom
in interfaceIColorCenter<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
- Specified by:
filter
in interfaceIColorCenter<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 interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Parameters:
ics
- an IColoredString, often produced byGDXMarkup.colorString(CharSequence)
.- Returns:
ics
filtered according tofilter(Color)
. May beics
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 interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Parameters:
color
- a T to copy; only the copy will be modifieddoAlpha
- Whether to include (and hereby change) the alpha component; if false alpha is kept as-is- Returns:
- A monochromatic variation of
t
.
-
get
-
get
-
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 interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Parameters:
start
- the initial Colorend
- the "target" colorchange
- 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 Colorend
- the "target" colorchange
- the degree to change closer to end; a change of 0.0 produces start, 1.0 produces end- Returns:
- a new Color
-
getRed
- Specified by:
getRed
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
-
getGreen
- Specified by:
getGreen
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
-
getBlue
- Specified by:
getBlue
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
-
getAlpha
- Specified by:
getAlpha
in interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
-
getHue
- Specified by:
getHue
in interfaceIColorCenter<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
- Specified by:
getSaturation
in interfaceIColorCenter<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
- Parameters:
r
- the red component in 0.0 to 1.0 range, typicallyg
- the green component in 0.0 to 1.0 range, typicallyb
- 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
- Parameters:
r
- the red component in 0.0 to 1.0 range, typicallyg
- the green component in 0.0 to 1.0 range, typicallyb
- 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
- Parameters:
r
- the red component in 0.0 to 1.0 range, typicallyg
- the green component in 0.0 to 1.0 range, typicallyb
- 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
- Specified by:
getValue
in interfaceIColorCenter<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
-
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 onlight
- the color of the light source- Returns:
- a copy of the Color color that factors in the lighting of the Color light.
-
light
Lightens a color by degree and returns the new color (mixed with white).- Parameters:
color
- the color to lightendegree
- 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
Lightens a color by degree and returns the new color (mixed with white).- Parameters:
color
- the color to lightendegree
- 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
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
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
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
Darkens a color by the specified degree and returns the new color (mixed with black).- Parameters:
color
- the color to darkendegree
- 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
Darkens a color by the specified degree and returns the new color (mixed with black).- Parameters:
color
- the color to darkendegree
- 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
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
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
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
Gets a fully-desaturated version of the given color (keeping its brightness, but making it grayscale).- Specified by:
desaturated
in interfaceIColorCenter<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 interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Parameters:
color
- the color to desaturatedegree
- 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 desaturatedegree
- 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
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 interfaceIColorCenter<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 interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Parameters:
color
- the color to saturatedegree
- 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 saturatedegree
- 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
Gets a fully random color that is only required to be opaque.- Returns:
- a random Color
-
randomize
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
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
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 inb
- another color to mix in- Returns:
- a random blend of a and b.
-
invert
-
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 interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Parameters:
fromColor
- the color to start with, included in the gradienttoColor
- 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 interfaceIColorCenter<com.badlogic.gdx.graphics.Color>
- Parameters:
fromColor
- the color to start with, included in the gradienttoColor
- the color to end on, included in the gradientsteps
- 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 gradientmidColor
- the color to use in the middle of the loop, included in the gradientsteps
- 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 gradienttoColor
- the color to end on, included in the gradientsteps
- the number of elements to use in the gradientinterpolation
- 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 gradientmidColor
- the color to use in the middle of the loop, included in the gradientsteps
- the number of elements to use in the gradient, will be at least 3interpolation
- 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
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 grayscalevalue
- the brightness of the rainbow's colors; 1.0 is brighteststeps
- 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 grayscalevalue
- the brightness of the rainbow's colors; 1.0 is brightestopacity
- the alpha value of all colors in the rainbow; 0.0 is fully transparent and 1.0 is opaquesteps
- 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 grayscalevalue
- the brightness of the rainbow's colors; 1.0 is brighteststeps
- 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 grayscalevalue
- the brightness of the rainbow's colors; 1.0 is brightestopacity
- the alpha value of all colors in the rainbow; 0.0 is fully transparent and 1.0 is opaquesteps
- 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 gradienttoColor
- the color to end on, included in the gradientsteps
- 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
-
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
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 callingclearCache()
), 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
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
-