Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Nightre/Rapid.js/llms.txt
Use this file to discover all available pages before exploring further.
Color represents an RGBA color with each component in the 0–255 range. Every time a component changes, the class automatically recomputes both a straight ABGR packed uint32 and a premultiplied-alpha ABGR packed uint32, so values are always ready for efficient GPU upload without extra conversion at draw time.
Constructor
Red component, 0–255.
Green component, 0–255.
Blue component, 0–255.
Alpha component, 0–255. Defaults to
255 (fully opaque).Static Factory Methods
Color.fromHex(hex)
Parse a CSS hex string into a Color. Supports both 6-character (#RRGGBB, fully opaque) and 8-character (#RRGGBBAA) forms. The leading # is optional.
Color.fromNorm(r, g, b, a?)
Create a Color from shader-style normalized floats in the 0.0–1.0 range. Each component is multiplied by 255 and rounded.
Color.FromRGB(r, g, b)
Alias for new Color(r, g, b). Creates a fully opaque color from 0–255 components.
Color.FromHSL(h, s, l)
Create a Color from HSL values. Hue is 0–360 degrees; saturation and lightness are 0–100 percent. Alpha is always 255.
Properties
Component Getters and Setters
Each component is exposed as a get/set pair. Writing a new value automatically triggers an update touint32 and premultipliedUint32.
| Property | Type | Description |
|---|---|---|
r | number | Red component (0–255). |
g | number | Green component (0–255). |
b | number | Blue component (0–255). |
a | number | Alpha component (0–255). |
uint32
A packed unsigned 32-bit integer in ABGR byte order representing the straight (non-premultiplied) color. Recomputed whenever any component changes. Used for fast vertex buffer writes.
premultipliedUint32
A packed unsigned 32-bit integer in ABGR byte order with RGB channels pre-multiplied by the alpha value. Used for correct alpha-blending in GPU pipelines that expect premultiplied input.
Methods
setRGBA(r, g, b, a)
Set all four components at once. Triggers a single uint32 recomputation rather than four individual ones.
setHSL(h, s, l)
Update the color in-place from HSL values (h: 0–360, s/l: 0–100). Sets alpha to 255. Returns this for chaining.
toHex()
Return an 8-character hex string in #RRGGBBAA format, always including alpha.
toHexString(includeAlpha?)
Return a hex string. When includeAlpha is true (default) the result is #RRGGBBAA; when false it is #RRGGBB.
equal(color) / equals(color)
Return true if all four RGBA components of color match this instance. equals is an alias for equal.
copy(color)
Copy all RGBA values from color into this instance, updating the uint32 cache.
clone()
Return a new Color with the same RGBA values.
add(color)
Return a new Color whose components are the sum of this color and color, clamped to 255.
subtract(color)
Return a new Color whose components are the difference, clamped to 0.
multiply(color | number)
Return a new Color with components multiplied component-wise by another Color, or scaled uniformly by a scalar. Does not clamp automatically — call clamp() on the result if needed.
divide(color | number)
Return a new Color with components divided component-wise by another Color or a scalar.
clamp()
Clamp all four components to the valid 0–255 range in-place. Useful after a series of arithmetic operations.
reset()
Reset all four components to their default values: r = 0, g = 0, b = 0, a = 255 (opaque black). Updates uint32 and premultipliedUint32 automatically.
setClearColor(gl)
Call gl.clearColor with this color’s components normalized to the 0.0–1.0 range. Convenience method for setting the WebGL canvas clear color directly from a Color instance.
Named Static Colors
Rapid.js ships predefinedColor constants for common colors. Each is a static property on the Color class.
| Constant | RGB |
|---|---|
Color.Red | (255, 0, 0) |
Color.Green | (0, 255, 0) |
Color.Blue | (0, 0, 255) |
Color.Yellow | (255, 255, 0) |
Color.Purple | (128, 0, 128) |
Color.Orange | (255, 165, 0) |
Color.Pink | (255, 192, 203) |
Color.Gray | (128, 128, 128) |
Color.Brown | (139, 69, 19) |
Color.Cyan | (0, 255, 255) |
Color.Magenta | (255, 0, 255) |
Color.Lime | (192, 255, 0) |
Color.White | (255, 255, 255) |
Color.Black | (0, 0, 0) |
Color.Transparent | (0, 0, 0, 0) |
Color.TRANSPARENT | (0, 0, 0, 0) |