Package squidpony
Interface IColorCenter<T>
- Type Parameters:
T
- The concrete type of colors
- All Known Implementing Classes:
IColorCenter.Skeleton
public interface IColorCenter<T>
How to manage colors, making sure that a color is allocated at most once.
If you aren't using squidlib's gdx part, you should use this interface (and
the IColorCenter.Skeleton
implementation), because it caches instances.
If you are using squidlib's gdx part, you should use this interface (and the
SquidColorCenter
implementation) if:
- You don't want to use preallocated instances (if you do, check out
squidpony.squidgrid.gui.Colors
) - You don't want to use named colors (if you do, check out
com.badlogic.gdx.graphics.Colors
) - You don't like libgdx's Color representation (components as floats in-between 0 and 1) but prefer components within 0 (inclusive) and 256 (exclusive); and don't mind the overhead of switching the representations. My personal opinion is that the overhead doesn't matter w.r.t other intensive operations that we have in roguelikes (path finding).
- Author:
- smelC
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
IColorCenter.Skeleton<T>
A skeletal implementation ofIColorCenter
. -
Method Summary
Modifier and Type Method Description T
desaturate(T color, float degree)
Brings a color closer to grayscale by the specified degree and returns the new color (desaturated somewhat).T
desaturated(T color)
Gets a fully-desaturated version of the given color (keeping its brightness, but making it grayscale).IColoredString<T>
filter(IColoredString<T> ics)
T
filter(T c)
T
get(int red, int green, int blue)
T
get(int red, int green, int blue, int opacity)
int
getAlpha(T c)
T
getBlack()
int
getBlue(T c)
int
getGreen(T c)
T
getHSV(float hue, float saturation, float value)
T
getHSV(float hue, float saturation, float value, float opacity)
float
getHue(T c)
T
getRandom(IRNG rng, int opacity)
int
getRed(T c)
float
getSaturation(T c)
T
getTransparent()
float
getValue(T c)
T
getWhite()
ArrayList<T>
gradient(T fromColor, T toColor)
Finds a gradient with 16 steps going from fromColor to toColor, both included in the gradient.ArrayList<T>
gradient(T fromColor, T toColor, int steps)
Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient.T
greify(T t, boolean doAlpha)
Gets a copy of t and modifies it to make a shade of gray with the same brightness.T
lerp(T start, T end, float change)
Gets the linear interpolation from Color start to Color end, changing by the fraction given by change.T
saturate(T 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).T
saturated(T color)
Fully saturates color (makes it a vivid color like red or green and less gray) and returns the modified copy.
-
Method Details
-
get
- 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).opacity
- The alpha component. In-between 0 (inclusive) and 256 (exclusive). Larger values mean more opacity; 0 is clear.- Returns:
- A possibly transparent color.
-
get
- 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
- 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
- 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
- Returns:
- Opaque white.
-
getBlack
- Returns:
- Opaque black.
-
getTransparent
- Returns:
- The fully transparent color.
-
getRandom
- Parameters:
rng
- an RNG from SquidLib.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.
-
getRed
- Parameters:
c
- a concrete color- Returns:
- The red component. For screen colors, in-between 0 (inclusive) and 256 (exclusive).
-
getGreen
- Parameters:
c
- a concrete color- Returns:
- The green component. For screen colors, in-between 0 (inclusive) and 256 (exclusive).
-
getBlue
- Parameters:
c
- a concrete color- Returns:
- The blue component. For screen colors, in-between 0 (inclusive) and 256 (exclusive).
-
getAlpha
- Parameters:
c
- a concrete color- Returns:
- The alpha component. In-between 0 (inclusive) and 256 (exclusive).
-
getHue
- 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
- 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)
-
getValue
- Parameters:
c
- a concrete color- Returns:
- the value (essentially lightness) of the color from 0.0 (black, inclusive) to 1.0 (very bright, inclusive).
-
filter
- Parameters:
c
-- Returns:
- The color that
this
shows whenc
is requested. May bec
itself.
-
filter
- Parameters:
ics
-- Returns:
ics
filtered according tofilter(Object)
. May beics
itself if unchanged.
-
greify
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. Not related to reified types or any usage of "reify."- Parameters:
t
- a T to copy; only the copy will be modifieddoAlpha
- Whether to include (and hereby change) the alpha component.- Returns:
- A monochromatic variation of
t
.
-
lerp
Gets the linear interpolation from Color start to Color end, changing by the fraction given by change.- Parameters:
start
- the initial color Tend
- the "target" color Tchange
- the degree to change closer to end; a change of 0.0f produces start, 1.0f produces end- Returns:
- a new T between start and end
-
desaturated
Gets a fully-desaturated version of the given color (keeping its brightness, but making it grayscale). Keeps alpha the same; if you want alpha to be considered (and brightness to be calculated differently), then you can use greify() in this class instead.- Parameters:
color
- the color T to desaturate (will not be modified)- Returns:
- the grayscale version of color
-
desaturate
Brings a color closer to grayscale by the specified degree and returns the new color (desaturated somewhat). Alpha is left unchanged.- Parameters:
color
- the color T 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 T
-
saturated
Fully saturates color (makes it a vivid color like red or green and less gray) and returns the modified copy. Leaves alpha unchanged.- Parameters:
color
- the color T to saturate (will not be modified)- Returns:
- the saturated version of color
-
saturate
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 does not necessarily return a specific color, but most implementations will treat a hue of 0 as red.- Parameters:
color
- the color T 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
-
gradient
Finds a gradient with 16 steps going from fromColor to toColor, both included in the gradient.- Parameters:
fromColor
- the color to start with, included in the gradienttoColor
- the color to end on, included in the gradient- Returns:
- an ArrayList composed of the blending steps from fromColor to toColor, with length equal to steps
-
gradient
Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient.- 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
-