Skip to main content
Color represents an RGBA color with four uint8 components - r, g, b, a, each in the range 0–255. Every render function, ESP element, and visual effect uses this type.
The default alpha is 255 (fully opaque). A freshly constructed new Color() is white (255, 255, 255, 255), not transparent.

Overview

Creating colors

RGBA, hex, arrays, objects, HSV, HSL, and float forms.

Arithmetic

Add, subtract, scale - all return new instances.

Modification

Alpha override, brightness, and interpolation.

Conversion

HSV, packed integers, arrays, and string output.

Presets

Built-in white, black, red, green.

Properties


Creating colors

Seven forms - pick whatever fits your data source.

Constructor


Creates a new Color. Missing components default to 255.

Color.fromHex


Creates a color from a hex string (e.g. "#FF0000", "FF0000FF") or a packed hex integer.

Color.fromHSV


Creates a color from Hue-Saturation-Value. Alpha defaults to 1.0.
HSV is ideal for cycling through hues - just animate the h parameter from 0 to 360 for a rainbow effect.

Color.fromHSL


Creates a color from Hue-Saturation-Lightness. Alpha defaults to 1.0.

Color.fromFloat


Creates a color from floating-point components in the 0–1 range. Alpha defaults to 1.0.

Presets

Static factories for common colors. All return a new Color instance with alpha 255.
Presets create a new instance every call - safe to modify without affecting future calls: const c = Color.red(); c.a = 128; is fine.

Arithmetic

All arithmetic methods return a new Color. Components are clamped to 0–255 internally.

add


Component-wise addition. Each channel is clamped to 0–255.

sub


Component-wise subtraction. Each channel is clamped to 0–255.

mul


Multiplies RGB channels by a scalar. Alpha is unchanged. Returns a new Color.

Modification

These methods create variations of a color - adjusting alpha, brightness, or blending with another color. All return a new Color.

withAlpha


Returns a copy with a different alpha. Accepts either a 0–255 integer or a 0.0–1.0 float. The engine auto-detects: if the value is a float in [0.0, 1.0] (and not an integer), it’s treated as a fraction. Otherwise it’s a byte.
The value 1 is ambiguous - it could mean “1 out of 255” or “100% opacity”. The engine treats integer 1 as the byte value 1 (nearly invisible). Use 1.0 for full opacity, or 255 to be explicit.

brightness


Scales the RGB brightness by factor. A factor of 0.5 halves the brightness, 2.0 doubles it. Alpha is unchanged. Returns a new Color.

lerp


Linear interpolation between this color and other. t=0 returns this color, t=1 returns other, t=0.5 returns the midpoint. All four channels (including alpha) are interpolated.

Conversion

toHSV


Converts to Hue-Saturation-Value. Returns a plain object.
Round-trip works: Color.fromHSV(c.toHSV().h, c.toHSV().s, c.toHSV().v) gives back the same color (within rounding). Useful for hue-shifting: modify h, then convert back.

toRGBA


Returns a packed 32-bit integer in RGBA byte order.

toARGB


Returns a packed 32-bit integer in ARGB byte order.

toImU32


Returns the color as an ImGui-compatible packed integer (ImU32, ABGR byte order). You rarely need this directly - render functions accept Color objects natively.

equals


Exact equality - all four channels must match. Returns false if other is not a Color.

clone


Returns an independent deep copy.

toArray


Returns [r, g, b, a] as a plain array.

toString


Returns a human-readable string.

Common patterns