Class ColorGradient
java.lang.Object
net.ixdarklord.coolcatcanvas.api.utils.ColorGradient
An animated color gradient: color stops placed evenly around a loop (the last blends back into the first, so it
never jumps), or the full rainbow of hues. The loop scrolls over time (
speed()) and
along a position (spread()): a character's index in the text, or the distance around an
Outline.
ColorGradient.of(0xFF4000, 0xFFD000) // fire: orange to yellow and back, each letter its own color
ColorGradient.RAINBOW.wholeText() // the whole text in one color, cycling through the rainbow
ColorGradient.of(0x40C0FF, 0xFFFFFF).withSpeed(0).perLetter(10) // a still gradient, repeating every 10 letters
Components can use one as their color: apply(MutableComponent), literal(String) or a style with
textColor() make the text animate wherever it's drawn (chat, tooltips, item names, signs, widget labels).
The color is saved and sent by name, so it also works in JSON text and commands:
coolcatlib:rainbow(RAINBOW),coolcatlib:rainbow_whole(RAINBOW_WHOLE)coolcatlib:rainbow/<speed>/<spread>/<saturation>/<brightness>, trailing values optionalcoolcatlib:gradient/<speed>/<spread>/#RRGGBB/#RRGGBB...
/tellraw @a {"text":"Hi","color":"coolcatlib:gradient/0.5/0.05/#FF4000/#FFD000"}. Players
without CoolCatLib can't read these colors, so only send them to players who have it.
Stop colors are RGB; their alpha is ignored (text and outlines bring their own).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ColorGradientGreen, teal and violet.static final floatstatic final floatstatic final ColorGradientRed, orange and yellow.static final ColorGradientDeep blue to cyan.static final ColorGradientA softer rainbow.static final ColorGradientEvery hue, each letter its own color, a full rainbow every 20 letters, flowing at half a cycle per second.static final ColorGradientThe whole text in one color, cycling through the rainbow at half a cycle per second. -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.network.chat.MutableComponentapply(net.minecraft.network.chat.MutableComponent component) Colors the component (and the children that don't set their own color) with this gradient.net.minecraft.network.chat.StyleapplyTo(net.minecraft.network.chat.Style style) The style with this gradient as its color.floatintcolor(float position) The opaque ARGB color at a position, right now.intcolor(float position, int alpha) The ARGB color at a position, right now, with the given alpha (0-255).int[]colors()The RGB color stops, or an empty array for a rainbow.booleanstatic Optional<ColorGradient> fromTextColor(net.minecraft.network.chat.TextColor color) The gradient a text color draws as, if it's one made bytextColor().inthashCode()booleanbooleannet.minecraft.network.chat.MutableComponentA literal text in this gradient.static ColorGradientof(int... colors) A gradient through the given RGB colors, looping back to the first.perLetter(int letters) Each letter its own color, the whole gradient everylettersletters.floatprogress(float position) How far along the loop (0-1) a position is, right now.static ColorGradientrainbow()Every hue, likeRAINBOW.static ColorGradientrainbow(float saturation, float brightness) Every hue at the given saturation (0 white to 1 full color) and brightness (0 black to 1 full).intsample(float progress) The RGB color at a point of the loop (0-1), ignoring time and spread.floatfloatspeed()floatspread()net.minecraft.network.chat.TextColorA text color that draws as this gradient, one step per character.toString()net.minecraft.network.chat.MutableComponenttranslatable(String key, Object... args) A translated text in this gradient.The whole text in one color, cycling through the gradient (a spread of 0).withBrightness(float brightness) For a rainbow: its brightness, 0 (black) to 1 (full).withSaturation(float saturation) For a rainbow: its saturation, 0 (white) to 1 (full color).withSpeed(float speed) Full loops per second; negative runs backwards, 0 stands still.withSpread(float spread) How far along the loop each step of position moves, in loops (0.05 = the whole gradient every 20 letters).
-
Field Details
-
DEFAULT_SPEED
public static final float DEFAULT_SPEED- See Also:
-
DEFAULT_SPREAD
public static final float DEFAULT_SPREAD- See Also:
-
RAINBOW
Every hue, each letter its own color, a full rainbow every 20 letters, flowing at half a cycle per second. -
RAINBOW_WHOLE
The whole text in one color, cycling through the rainbow at half a cycle per second. -
PASTEL_RAINBOW
A softer rainbow. -
FIRE
Red, orange and yellow. -
OCEAN
Deep blue to cyan. -
AURORA
Green, teal and violet.
-
-
Method Details
-
of
A gradient through the given RGB colors, looping back to the first. One color is a solid color; to fade between two colors without looping through them twice, just give the two. -
rainbow
Every hue, likeRAINBOW. -
rainbow
Every hue at the given saturation (0 white to 1 full color) and brightness (0 black to 1 full). -
withSpeed
Full loops per second; negative runs backwards, 0 stands still. -
withSpread
How far along the loop each step of position moves, in loops (0.05 = the whole gradient every 20 letters). -
perLetter
Each letter its own color, the whole gradient everylettersletters. -
wholeText
The whole text in one color, cycling through the gradient (a spread of 0). -
withSaturation
For a rainbow: its saturation, 0 (white) to 1 (full color). No effect on a gradient of colors. -
withBrightness
For a rainbow: its brightness, 0 (black) to 1 (full). No effect on a gradient of colors. -
speed
public float speed() -
spread
public float spread() -
saturation
public float saturation() -
brightness
public float brightness() -
isRainbow
public boolean isRainbow() -
isWholeText
public boolean isWholeText() -
colors
public int[] colors()The RGB color stops, or an empty array for a rainbow. -
progress
public float progress(float position) How far along the loop (0-1) a position is, right now. -
color
public int color(float position) The opaque ARGB color at a position, right now. -
color
public int color(float position, int alpha) The ARGB color at a position, right now, with the given alpha (0-255). -
sample
public int sample(float progress) The RGB color at a point of the loop (0-1), ignoring time and spread. -
textColor
public net.minecraft.network.chat.TextColor textColor()A text color that draws as this gradient, one step per character. -
applyTo
public net.minecraft.network.chat.Style applyTo(net.minecraft.network.chat.Style style) The style with this gradient as its color. -
apply
public net.minecraft.network.chat.MutableComponent apply(net.minecraft.network.chat.MutableComponent component) Colors the component (and the children that don't set their own color) with this gradient. -
literal
A literal text in this gradient. -
translatable
-
fromTextColor
The gradient a text color draws as, if it's one made bytextColor(). -
equals
-
hashCode
-
toString
-