Package squidpony
Class IColorCenter.Skeleton<T>
java.lang.Object
squidpony.IColorCenter.Skeleton<T>
- Type Parameters:
T
- a concrete color type
- All Implemented Interfaces:
IColorCenter<T>
- Enclosing interface:
- IColorCenter<T>
public abstract static class IColorCenter.Skeleton<T> extends Object implements IColorCenter<T>
A skeletal implementation of
IColorCenter
.- Author:
- smelC
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
IColorCenter.Skeleton.GranularHasher
-
Field Summary
Fields Modifier and Type Field Description protected IFilter<T>
filter
protected IColorCenter.Skeleton.GranularHasher
theHasher
-
Constructor Summary
-
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(IColorCenter.Skeleton<T> 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.protected abstract T
create(int red, int green, int blue, int opacity)
Create a concrete instance of the color type given as a type parameter.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)
T
getBlack()
T
getHSV(float hue, float saturation, float value)
T
getHSV(float hue, float saturation, float value, float opacity)
float
getHue(float r, float g, float b)
float
getHue(T c)
T
getRandom(IRNG rng, int opacity)
float
getSaturation(float r, float g, float b)
float
getSaturation(T c)
T
getTransparent()
protected long
getUniqueIdentifier(int r, int g, int b, int a)
protected long
getUniqueIdentifier(T item)
float
getValue(float r, float g, float b)
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.IColorCenter.Skeleton<T>
setFilter(IFilter<T> filter)
If you're changing the filter, you should likely callclearCache()
.
-
Field Details
-
Constructor Details
-
Skeleton
- Parameters:
filter
- The filter to use, ornull
for no filter.
-
-
Method Details
-
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
-
setFilter
If you're changing the filter, you should likely callclearCache()
.- Parameters:
filter
- The filter to use, ornull
to turn filtering OFF.- Returns:
this
-
get
- Specified by:
get
in interfaceIColorCenter<T>
- 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
- Specified by:
get
in interfaceIColorCenter<T>
- 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
- Specified by:
getHSV
in interfaceIColorCenter<T>
- 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<T>
- 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<T>
- Returns:
- Opaque white.
-
getBlack
- Specified by:
getBlack
in interfaceIColorCenter<T>
- Returns:
- Opaque black.
-
getTransparent
- Specified by:
getTransparent
in interfaceIColorCenter<T>
- Returns:
- The fully transparent color.
-
getRandom
- Specified by:
getRandom
in interfaceIColorCenter<T>
- 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.
-
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)
-
getSaturation
- Specified by:
getSaturation
in interfaceIColorCenter<T>
- 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:
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).
-
getValue
- Specified by:
getValue
in interfaceIColorCenter<T>
- Parameters:
c
- a concrete color- 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)
-
getHue
- Specified by:
getHue
in interfaceIColorCenter<T>
- 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)
-
filter
- Specified by:
filter
in interfaceIColorCenter<T>
- Returns:
- The color that
this
shows whenc
is requested. May bec
itself.
-
filter
- Specified by:
filter
in interfaceIColorCenter<T>
- Returns:
ics
filtered according toIColorCenter.filter(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."- Specified by:
greify
in interfaceIColorCenter<T>
- 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. This implementation tries to work with colors in a way that is as general as possible, using getRed() instead of some specific detail that depends on how a color is implemented. Other implementations that specialize in a specific type of color may be able to be more efficient.- Specified by:
lerp
in interfaceIColorCenter<T>
- 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.- Specified by:
desaturated
in interfaceIColorCenter<T>
- 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.- Specified by:
desaturate
in interfaceIColorCenter<T>
- 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.- Specified by:
saturated
in interfaceIColorCenter<T>
- 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 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<T>
- 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
Description copied from interface:IColorCenter
Finds a gradient with 16 steps going from fromColor to toColor, both included in the gradient.- Specified by:
gradient
in interfaceIColorCenter<T>
- 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
Description copied from interface:IColorCenter
Finds a gradient with the specified number of steps going from fromColor to toColor, both included in the gradient.- Specified by:
gradient
in interfaceIColorCenter<T>
- 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
-
create
Create a concrete instance of the color type given as a type parameter. That's the place to use thefilter
.- Parameters:
red
- the red component of the desired colorgreen
- the green component of the desired colorblue
- the blue component of the desired coloropacity
- the alpha component or opacity of the desired color- Returns:
- a fresh instance of the concrete color type
-
getUniqueIdentifier
-
getUniqueIdentifier
-