Class ColorGradient

java.lang.Object
net.ixdarklord.coolcatcanvas.api.utils.ColorGradient

public final class ColorGradient extends Object
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 optional
  • coolcatlib:gradient/<speed>/<spread>/#RRGGBB/#RRGGBB...
e.g. /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

    Fields
    Modifier and Type
    Field
    Description
    static final ColorGradient
    Green, teal and violet.
    static final float
     
    static final float
     
    static final ColorGradient
    Red, orange and yellow.
    static final ColorGradient
    Deep blue to cyan.
    static final ColorGradient
    A softer rainbow.
    static final ColorGradient
    Every hue, each letter its own color, a full rainbow every 20 letters, flowing at half a cycle per second.
    static final ColorGradient
    The whole text in one color, cycling through the rainbow at half a cycle per second.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    net.minecraft.network.chat.Style
    applyTo(net.minecraft.network.chat.Style style)
    The style with this gradient as its color.
    float
     
    int
    color(float position)
    The opaque ARGB color at a position, right now.
    int
    color(float position, int alpha)
    The ARGB color at a position, right now, with the given alpha (0-255).
    int[]
    The RGB color stops, or an empty array for a rainbow.
    boolean
     
    fromTextColor(net.minecraft.network.chat.TextColor color)
    The gradient a text color draws as, if it's one made by textColor().
    int
     
    boolean
     
    boolean
     
    net.minecraft.network.chat.MutableComponent
    A literal text in this gradient.
    of(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 every letters letters.
    float
    progress(float position)
    How far along the loop (0-1) a position is, right now.
    Every hue, like RAINBOW.
    rainbow(float saturation, float brightness)
    Every hue at the given saturation (0 white to 1 full color) and brightness (0 black to 1 full).
    int
    sample(float progress)
    The RGB color at a point of the loop (0-1), ignoring time and spread.
    float
     
    float
     
    float
     
    net.minecraft.network.chat.TextColor
    A text color that draws as this gradient, one step per character.
     
    net.minecraft.network.chat.MutableComponent
    translatable(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).

    Methods inherited from class Object

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

    • DEFAULT_SPEED

      public static final float DEFAULT_SPEED
      See Also:
    • DEFAULT_SPREAD

      public static final float DEFAULT_SPREAD
      See Also:
    • RAINBOW

      public static final ColorGradient RAINBOW
      Every hue, each letter its own color, a full rainbow every 20 letters, flowing at half a cycle per second.
    • RAINBOW_WHOLE

      public static final ColorGradient RAINBOW_WHOLE
      The whole text in one color, cycling through the rainbow at half a cycle per second.
    • PASTEL_RAINBOW

      public static final ColorGradient PASTEL_RAINBOW
      A softer rainbow.
    • FIRE

      public static final ColorGradient FIRE
      Red, orange and yellow.
    • OCEAN

      public static final ColorGradient OCEAN
      Deep blue to cyan.
    • AURORA

      public static final ColorGradient AURORA
      Green, teal and violet.
  • Method Details

    • of

      public static ColorGradient of(int... colors)
      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

      public static ColorGradient rainbow()
      Every hue, like RAINBOW.
    • rainbow

      public static ColorGradient rainbow(float saturation, float brightness)
      Every hue at the given saturation (0 white to 1 full color) and brightness (0 black to 1 full).
    • withSpeed

      public ColorGradient withSpeed(float speed)
      Full loops per second; negative runs backwards, 0 stands still.
    • withSpread

      public ColorGradient withSpread(float spread)
      How far along the loop each step of position moves, in loops (0.05 = the whole gradient every 20 letters).
    • perLetter

      public ColorGradient perLetter(int letters)
      Each letter its own color, the whole gradient every letters letters.
    • wholeText

      public ColorGradient wholeText()
      The whole text in one color, cycling through the gradient (a spread of 0).
    • withSaturation

      public ColorGradient withSaturation(float saturation)
      For a rainbow: its saturation, 0 (white) to 1 (full color). No effect on a gradient of colors.
    • withBrightness

      public ColorGradient withBrightness(float brightness)
      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

      public net.minecraft.network.chat.MutableComponent literal(String text)
      A literal text in this gradient.
    • translatable

      public net.minecraft.network.chat.MutableComponent translatable(String key, Object... args)
      A translated text in this gradient.
    • fromTextColor

      public static Optional<ColorGradient> fromTextColor(net.minecraft.network.chat.TextColor color)
      The gradient a text color draws as, if it's one made by textColor().
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object