Gradients
red.jackf.jackfredlib.api.colour.Gradient
Last updated
red.jackf.jackfredlib.api.colour.Gradient
Last updated
Gradient
s are sequences of Colour
s from a range of 0 to 1. They can be sampled at any given point between that range (with it looping in the case of being outside that range).
Colour
s also implement the Gradient
interface, allowing them to be substituted for any methods taking a gradient.
JFL: Colour has 3 modes for interpolating between two colours in gradients:
RGB: Regular linear interpolation for all components
HSV_SHORT: Linear intepolation in the HSV space, taking the shortest path. This has the effect of keeping the colours bright instead of greying in the middle.
HSV_LONG: Linear interpolation in the HSV space, taking the longest path.
Currently, alpha values are always set to maximum when used in a HSV gradient. This may change in the future.
HSV gradients are not stored as such - they're immediately compiled into an equivalent series of RGB gradients which look identical. As such, the HSV points cannot be returned back.
Gradient.of()
For simple gradients, using Gradient.of()
is likely the easiest method. This generates a gradient with equal intervals between colours and RGB blending.
Gradient.linear()
Using Gradient.linear()
creates a gradient between two points, using either RGB or HSV blending modes. For examples of these, see above.
Gradient.builder()
For more control, you can use the given GradientBuilder
class in order to create one point by point.
It may be useful to modify a gradient after it's been created - you can use it in GradientBuilder.addBlock
, or some post-processing methods:
squish()
If your gradient has sharp edges, you can squish
it in order to make transitions smoother. It does this by shrinking it slightly towards the center, then adding points at 0f
and GradientBuilder.END
with a lerped colour value.
repeat()
Returns a copy of this gradient shrunken and repeated a certain number of times back to back.
reversed()
Reverses this gradient.
slice()
Returns a subsection of this gradient between the two points. These points can be backwards, and can cross the edges of the gradient boundary. Note that it will not automatically repeat the gradient but will wrap instead.
JFL: Colour contains methods to efficiently draw gradients in a GUI context, horizontally and vertically. These methods are client-only, and can be found under GradientUtils
. This can draw gradients repeated or backwards depending on what you pass for gradientStart
and gradientEnd
.
These methods use a single quad for each RGB segment.
squish
ed by 0.1f