Skip to content

Colors and Gradients

ssbaxys edited this page Oct 26, 2026 · 1 revision

Colors in different color spaces, gradients and brushes.

Colors (render.Color)

A color is a plain ARGB int, with no objects and no allocations.

Color.rgb(255, 128, 0);  Color.rgba(255, 128, 0, 0.5f);  Color.hex("#5B8CFF");
Color.hsv(200, 0.8f, 1f);  Color.hsl(200, 0.8f, 0.6f);  Color.oklch(0.7f, 0.15f, 250);
Color.parse("rgb(255 128 0 / 50%)");  Color.parse("hsl(200, 80%, 60%)");  Color.parse("tomato");
Color.rainbow(t);                        // rainbow for t ∈ [0, 1]

Operations are computed in OKLCH, so "10% lighter" looks the same for any hue: lighten, darken, saturate, desaturate, rotateHue, withHue, complement, grayscale, invert, withAlpha, mulAlpha, luminance, contrast (WCAG), readableOn (black or white text on a background), over (compositing). Mixing: Color.lerp(a, b, t) (sRGB), Color.mix(a, b, t) (OKLAB), Color.lerp(a, b, t, ColorSpace.OKLCH).

The hex format matches a Java int: #AARRGGBB (or #RRGGBB).

Brushes and gradients (render.Brush)

Brush Example
Solid Brush.solid(0xFF5B8CFF)
Linear Brush.linear(135, a, b, c), Brush.vertical(a, b), Brush.horizontal(a, b)
Radial Brush.radial(center, edge), .at(0.3f, 0.3f), .withRadius(0.7f, 0.35f) (ellipse)
Conic Brush.conic(angle, colors...), Brush.rainbowWheel()
  • Up to 8 colors, arbitrary positions and hard stops: ColorStops.builder().add(0, a).hard(0.5f, a, b).add(1, b).build().
  • .withRepeating(true) repeats the pattern (stripes, rings), .withOffset(x) shifts it (moving stripes).
  • .inSpace(ColorSpace.OKLAB / OKLCH / LINEAR / HSV / SRGB) picks the mixing color space.
  • Angles work as in CSS: 0° points up, 90° points right.
  • Ready-made sets are in Gradients: SUNSET, OCEAN, AURORA, NEON, FIRE, MINT, PEACH, NIGHT, GOLD, BERRY, LIME, RAINBOW.

Gradients are computed per pixel in the SDF shader, with dithering against banding. Simple two-color linear gradients take a fast path through vertex colors. Brushes can be animated (Brush.lerp), including the transition solid ↔ gradient.

Canvas also has drawArc (arcs with a gradient), fillCircle and strokeCircle, drawLine, fillTriangle, fillQuad, drawTextureQuad (a texture on an arbitrary quad), drawItem("minecraft:tnt", x, y, size) and setBlendMode(NORMAL | ADD | MULTIPLY | SCREEN).


← Styles and Themes · English home · Animations →

Clone this wiki locally