Skip to content

Color

final class Color
Extends: LockableValue<Color>
Package: dev.joid.lib.color · Module: core · Source: Color.java

An RGBA color with channels on 1, which can also hold a linear gradient or change on every frame.

Every color setter of JOID takes a Color. Create one from a hex string, from channels, or take a named constant (Create a color).

An animated color, such as Color.RAINBOW, carries an update function that JOID applies each time it draws the color. Two colors are equal when their channels, their gradient and their update function are equal; the update function compares by identity.

ReturnsSignatureSummary
Colorrgb(int value) factoryCreates an opaque color from a packed 0xRRGGBB value; the top byte is ignored.
Colorargb(int value) factoryCreates a color from a packed 0xAARRGGBB value, alpha in the top byte.
Colordecode(String nm) factoryParses a color from text, with or without #: #RRGGBB (opaque), #RRGGBBAA (alpha last), rgb(r, g, b) with channels from 0 to 255, rgba(r, g, b, a) with an alpha on 1, gradient(from, to) for a left-to-right gradient or gradient(from, to, x1, y1, x2, y2) with a direction (see toGradient), and rainbow or loading for a copy of the animated constants.
ColorRAINBOW() factoryReturns the color of the rainbow cycle at this instant of the JOID clock: a full turn of hues every 3 seconds.
ColorRAINBOW(long time) factoryReturns the color of the rainbow cycle at time, in milliseconds of the JOID clock.
ColorLOADING() factoryReturns the color of the loading pulse at this instant: a dark gray that brightens and darkens slightly, one cycle every 2 seconds.
Color(FloatBuffer buffer)Reads red, green, blue and alpha on 1 from the current position of the buffer, which advances by four floats.
Color(java.awt.Color color)Converts a java.awt.Color.
Color(ColorGradient gradient)Creates a gradient color from a ColorGradient; its own channels are those of the start color.
Color(int r, int g, int b)Creates an opaque color from red, green and blue from 0 to 255.
Color(float r, float g, float b)Creates an opaque color from red, green and blue on 1.
Color(int r, int g, int b, int a)Creates a color from red, green, blue and alpha from 0 to 255.
Color(float r, float g, float b, float a)Creates a color from red, green, blue and alpha on 1.
Color(float r, float g, float b, float a, UnaryOperator update)Creates an animated color: each time JOID draws it, JOID passes this color to update and draws the color that it returns.

PropertyTypeDefaultSummary
redfloatset at creationThe red channel: getRed() reads it from 0 to 255, getRedF() on 1.
bluefloatset at creationThe blue channel: getBlue() reads it from 0 to 255, getBlueF() on 1.
alphafloat255The opacity: getAlpha() reads it from 0 to 255, getAlphaF() on 1, where 0F is fully transparent.
greenfloatset at creationThe green channel: getGreen() reads it from 0 to 255, getGreenF() on 1.

ReturnsSignatureSummary
voidbind()Sets the color of the render state to the current frame of this color.
voidbind(Runnable runnable, BoundingBox canvas)Runs runnable with this color applied, then restores the previous color of the render state.
voidbind(Runnable runnable, BoundingBox canvas, boolean hasTexture)Runs runnable with this color applied, then restores the previous color; if hasTexture is true, a gradient multiplies the bound texture instead of replacing it, which tints an image.
ReturnsSignatureSummary
intgetRGB()Returns the color packed as 0xAARRGGBB.
floatgetRedF()Returns the red channel on 1.
floatgetBlueF()Returns the blue channel on 1.
floatgetAlphaF()Returns the alpha channel on 1.
floatgetGreenF()Returns the green channel on 1.
thisto(Color target, float progress) fluentReturns the color between this one and target at progress on 1: 0F gives a copy of this color, 1F a copy of target, alpha included.
thistoGradient(Color target) fluentReturns a left-to-right gradient from this color to target.
ColortoGradient(Color target, Point startPoint, Point endPoint)Returns a gradient from this color to target along the line from startPoint to endPoint.
booleanisGradient()If true, this color holds a ColorGradient and draws as a gradient.
StringtoString()Returns the channels from 0 to 255 and the #RRGGBBAA form, for logs.
ColorGradientgetGradient()Returns the gradient of this color, or null for a plain color.
ReturnsSignatureSummary
Stringencode()Returns the color as #RRGGBBAA in upper case, the format that decode reads back.
thisdarker() fluentReturns this color darkened by half (darker(0.5F)).
thisdarker(float scale) fluentReturns this color with red, green and blue multiplied by 1 - scale; alpha is unchanged.
thisbrighter() fluentReturns this color brightened by 20 % (brighter(0.2F)).
thisbrighter(float scale) fluentReturns this color with red, green and blue multiplied by 1 + scale, clamped to 1F; alpha is unchanged.
thismultiply(Color c) fluentReturns this color multiplied channel by channel, alpha included, by c.
thisadd(Color c) fluentReturns the sum of this color and c channel by channel, alpha included, clamped to 1F.
thisscale(float value) fluentReturns this color with every channel, alpha included, multiplied by value.
float[]RGBtoHSB(float[] hsbvals)Returns the hue, saturation and brightness of this color, each on 1, in hsbvals when it is not null, otherwise in a new array.
float[]RGBtoHSB(int r, int g, int b, float[] hsbvals) staticConverts red, green and blue from 0 to 255 to hue, saturation and brightness on 1, written in hsbvals when it is not null, otherwise in a new array.
thiswithRed(float red) fluentReturns a copy with the red channel set to red, on 1.
thiswithBlue(float blue) fluentReturns a copy with the blue channel set to blue, on 1.
ColorwithAlpha(float alpha)Returns a copy with the opacity set to alpha, on 1.
thiswithGreen(float green) fluentReturns a copy with the green channel set to green, on 1.
Colorcopy()Returns an unlocked copy that keeps the gradient and the update function.
voidreset() staticSets the color of the render state back to opaque white, the color that leaves textures and vertex colors unchanged.
booleanequals(Object other)If true, the other object is of the same class with the same channels, update and gradient; the name of a constant is ignored.
inthashCode()Returns a hash of the values that equals compares.
thisupdate() fluentReturns the frame of this color at this instant: the color itself when it is not animated, otherwise a fixed color computed by its update function.
Inherited from LockableValue (2)

lock · isLocked

TypeNameValueSummary
ColorREDnew Color(1F, 0F, 0F, 1F).constant("RED")Opaque red, #FF0000FF.
ColorBLUEnew Color(0F, 0F, 1F, 1F).constant("BLUE")Opaque blue, #0000FFFF.
ColorGRAYnew Color(0.5F, 0.5F, 0.5F, 1F).constant("GRAY")Opaque mid gray, 0.5F on every channel.
ColorCYANnew Color(0F, 1F, 1F, 1F).constant("CYAN")Opaque cyan, #00FFFFFF.
ColorPINKnew Color(1F, 0.7F, 0.7F, 1F).constant("PINK")Opaque light pink: red 1F, green and blue 0.7F.
ColorWHITEnew Color(1F, 1F, 1F, 1F).constant("WHITE")Opaque white, #FFFFFFFF.
ColorGREENnew Color(0F, 1F, 0F, 1F).constant("GREEN")Opaque green, #00FF00FF.
ColorBLACKnew Color(0F, 0F, 0F, 1F).constant("BLACK")Opaque black, #000000FF.
ColorYELLOWnew Color(1F, 1F, 0F, 1F).constant("YELLOW")Opaque yellow, #FFFF00FF.
ColorORANGEnew Color(1F, 0.5F, 0F, 1F).constant("ORANGE")Opaque orange: red 1F, green 0.5F, blue 0F.
ColorMAGENTAnew Color(1F, 0F, 1F, 1F).constant("MAGENTA")Opaque magenta, #FF00FFFF.
ColorDARKGRAYnew Color(0.3F, 0.3F, 0.3F, 1F).constant("DARKGRAY")Opaque dark gray, 0.3F on every channel.
ColorLIGHTGRAYnew Color(0.7F, 0.7F, 0.7F, 1F).constant("LIGHTGRAY")Opaque light gray, 0.7F on every channel.
ColorTRANSPARENTnew Color(0F, 0F, 0F, 0F).constant("TRANSPARENT")Fully transparent black: draws nothing.
ColorRAINBOWAn animated color that cycles through the hues every 3 seconds, at 80 % saturation and brightness; its alpha is kept.
ColorLOADINGAn animated color that pulses slightly around a dark gray every 2 seconds, the look of a loading placeholder; its alpha is kept.

Color rgb(int value) factory

Creates an opaque color from a packed 0xRRGGBB value; the top byte is ignored.

Color argb(int value) factory

Creates a color from a packed 0xAARRGGBB value, alpha in the top byte.

Color decode(String nm) factory

Throws:

  • NumberFormatException: The color … cannot be decoded, write it as #RRGGBB, #RRGGBBAA, rgb(r, g, b), rgba(r, g, b, a) or gradient(from, to)

Parses a color from text, with or without #: #RRGGBB (opaque), #RRGGBBAA (alpha last), rgb(r, g, b) with channels from 0 to 255, rgba(r, g, b, a) with an alpha on 1, gradient(from, to) for a left-to-right gradient or gradient(from, to, x1, y1, x2, y2) with a direction (see toGradient), and rainbow or loading for a copy of the animated constants. Throws NumberFormatException for any other text.

Color RAINBOW() factory

Returns the color of the rainbow cycle at this instant of the JOID clock: a full turn of hues every 3 seconds. The result is a plain color that does not change: pass the constant Color.RAINBOW to a setter instead, so that the color cycles by itself.

Color RAINBOW(long time) factory

Returns the color of the rainbow cycle at time, in milliseconds of the JOID clock.

Color LOADING() factory

Returns the color of the loading pulse at this instant: a dark gray that brightens and darkens slightly, one cycle every 2 seconds. The result is a plain color: pass the constant Color.LOADING to a setter instead, so that the color pulses by itself.

Color(FloatBuffer buffer)

Reads red, green, blue and alpha on 1 from the current position of the buffer, which advances by four floats.

Color(java.awt.Color color)

Converts a java.awt.Color.

Color(ColorGradient gradient)

Creates a gradient color from a ColorGradient; its own channels are those of the start color.

Color(int r, int g, int b)

Creates an opaque color from red, green and blue from 0 to 255.

Color(float r, float g, float b)

Creates an opaque color from red, green and blue on 1.

Color(int r, int g, int b, int a)

Creates a color from red, green, blue and alpha from 0 to 255.

Color(float r, float g, float b, float a)

Creates a color from red, green, blue and alpha on 1. Every channel is clamped between 0F and 1F.

Color(float r, float g, float b, float a, UnaryOperator<Color> update)

Creates an animated color: each time JOID draws it, JOID passes this color to update and draws the color that it returns. A channel that you set later with red, green, blue or alpha overrides that channel on every frame.

  • this red(float red) fluent
  • int getRed()

Default: set at creation

The red channel: getRed() reads it from 0 to 255, getRedF() on 1. red(float) sets it in place, on 1, and throws IllegalStateException on a locked color such as a named constant.

  • this blue(float blue) fluent
  • int getBlue()

Default: set at creation

The blue channel: getBlue() reads it from 0 to 255, getBlueF() on 1. blue(float) sets it in place, on 1, and throws IllegalStateException on a locked color.

  • this alpha(float alpha) fluent
  • int getAlpha()

Default: 255

The opacity: getAlpha() reads it from 0 to 255, getAlphaF() on 1, where 0F is fully transparent. alpha(float) sets it in place, on 1, and throws IllegalStateException on a locked color.

  • this green(float green) fluent
  • int getGreen()

Default: set at creation

The green channel: getGreen() reads it from 0 to 255, getGreenF() on 1. green(float) sets it in place, on 1, and throws IllegalStateException on a locked color.

void bind()

Sets the color of the render state to the current frame of this color. Draws without a color of their own, such as images and Tessellator batches without vertex colors, are tinted by it.

void bind(Runnable runnable, BoundingBox canvas)

Runs runnable with this color applied, then restores the previous color of the render state. For a gradient, it binds the gradient shader instead, spread over canvas in the coordinates you draw in.

void bind(Runnable runnable, BoundingBox canvas, boolean hasTexture)

Runs runnable with this color applied, then restores the previous color; if hasTexture is true, a gradient multiplies the bound texture instead of replacing it, which tints an image.

int getRGB()

Returns the color packed as 0xAARRGGBB.

float getRedF()

Returns the red channel on 1.

float getBlueF()

Returns the blue channel on 1.

float getAlphaF()

Returns the alpha channel on 1.

float getGreenF()

Returns the green channel on 1.

this to(Color target, float progress) fluent

Returns the color between this one and target at progress on 1: 0F gives a copy of this color, 1F a copy of target, alpha included. Two gradients blend stop by stop and point by point; a plain color blends with each stop of a gradient. When either side is animated, the result is animated and blends the current frame of both sides.

this toGradient(Color target) fluent

Returns a left-to-right gradient from this color to target.

Color toGradient(Color target, Point startPoint, Point endPoint)

Returns a gradient from this color to target along the line from startPoint to endPoint. The points are on 1 of the drawn area: (0, 0) is its top-left corner and (1, 1) its bottom-right corner, so (0, 0) to (0, 1) runs from top to bottom.

boolean isGradient()

If true, this color holds a ColorGradient and draws as a gradient.

String toString()

Returns the channels from 0 to 255 and the #RRGGBBAA form, for logs.

ColorGradient getGradient()

Returns the gradient of this color, or null for a plain color.

String encode()

Returns the color as #RRGGBBAA in upper case, the format that decode reads back.

this darker() fluent

Returns this color darkened by half (darker(0.5F)).

this darker(float scale) fluent

Returns this color with red, green and blue multiplied by 1 - scale; alpha is unchanged.

this brighter() fluent

Returns this color brightened by 20 % (brighter(0.2F)).

this brighter(float scale) fluent

Returns this color with red, green and blue multiplied by 1 + scale, clamped to 1F; alpha is unchanged.

this multiply(Color c) fluent

Returns this color multiplied channel by channel, alpha included, by c.

this add(Color c) fluent

Returns the sum of this color and c channel by channel, alpha included, clamped to 1F.

this scale(float value) fluent

Returns this color with every channel, alpha included, multiplied by value.

float[] RGBtoHSB(float[] hsbvals)

Returns the hue, saturation and brightness of this color, each on 1, in hsbvals when it is not null, otherwise in a new array.

float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) static

Converts red, green and blue from 0 to 255 to hue, saturation and brightness on 1, written in hsbvals when it is not null, otherwise in a new array.

this withRed(float red) fluent

Returns a copy with the red channel set to red, on 1.

this withBlue(float blue) fluent

Returns a copy with the blue channel set to blue, on 1.

Color withAlpha(float alpha)

Returns a copy with the opacity set to alpha, on 1. On a gradient, both stops scale by the same factor, so their relative opacity is kept.

this withGreen(float green) fluent

Returns a copy with the green channel set to green, on 1.

Color copy()

Returns an unlocked copy that keeps the gradient and the update function. Copy a named constant before you change it with red, green, blue or alpha.

void reset() static

Sets the color of the render state back to opaque white, the color that leaves textures and vertex colors unchanged.

boolean equals(Object other)

If true, the other object is of the same class with the same channels, update and gradient; the name of a constant is ignored.

int hashCode()

Returns a hash of the values that equals compares.

this update() fluent

Returns the frame of this color at this instant: the color itself when it is not animated, otherwise a fixed color computed by its update function.

Color RED

Opaque red, #FF0000FF.

Color BLUE

Opaque blue, #0000FFFF.

Color GRAY

Opaque mid gray, 0.5F on every channel.

Color CYAN

Opaque cyan, #00FFFFFF.

Color PINK

Opaque light pink: red 1F, green and blue 0.7F.

Color WHITE

Opaque white, #FFFFFFFF.

Color GREEN

Opaque green, #00FF00FF.

Color BLACK

Opaque black, #000000FF.

Color YELLOW

Opaque yellow, #FFFF00FF.

Color ORANGE

Opaque orange: red 1F, green 0.5F, blue 0F.

Color MAGENTA

Opaque magenta, #FF00FFFF.

Color DARKGRAY

Opaque dark gray, 0.3F on every channel.

Color LIGHTGRAY

Opaque light gray, 0.7F on every channel.

Color TRANSPARENT

Fully transparent black: draws nothing.

Color RAINBOW

An animated color that cycles through the hues every 3 seconds, at 80 % saturation and brightness; its alpha is kept.

Color LOADING

An animated color that pulses slightly around a dark gray every 2 seconds, the look of a loading placeholder; its alpha is kept.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page