RGBA Class
TheRGBA class represents colors as normalized RGBA values (0.0 to 1.0). It uses a Float32Array internally for efficient FFI interop with the native rendering layer.
Constructor
constructor
Create an RGBA color from a Float32Array buffer
Float32Array
required
4-element array containing
[r, g, b, a] values (0.0 to 1.0)In most cases, use the static factory methods instead of calling the constructor directly.
Factory Methods
function
function
function
Create from a hex color stringReturns magenta (
string
required
Hex color:
"#RGB", "#RRGGBB", "#RGBA", or "#RRGGBBAA" (with or without #)#FF00FF) if the hex string is invalid.function
Create from an existing Float32Array
Properties
number
Red component (0.0 to 1.0)
number
Green component (0.0 to 1.0)
number
Blue component (0.0 to 1.0)
number
Alpha component (0.0 to 1.0)
Float32Array
Underlying storage buffer
Methods
function
Convert to integer RGBA valuesReturns an array of integers (0-255).
function
Convert to string representationReturns a string like
"rgba(0.50, 0.75, 1.00, 1.00)".function
Check equality with another colorReturns
true if all components are equal.function
Map a function over all componentsExample:
Color Utilities
Hex Conversion
function
Convert hex string to RGBASupports 3, 4, 6, and 8 character hex codes (with or without
#).function
Convert RGBA to hex stringReturns 6-character hex for opaque colors, 8-character for transparent.
Color Space Conversion
function
Color Parsing
function
Parse a color from string or RGBA objectSupports:
string | RGBA
required
Color to parse
- Hex colors:
"#FF0000","#F00", etc. - CSS color names:
"red","blue","transparent", etc. - Existing
RGBAobjects (returned as-is)
CSS Color Names
Supported color names:- Basic:
black,white,red,green,blue,yellow,cyan,magenta - Extended:
gray/grey,silver,maroon,olive,lime,aqua,teal,navy,fuchsia,purple,orange - Bright:
brightblack,brightred,brightgreen,brightblue,brightyellow,brightcyan,brightmagenta,brightwhite - Special:
transparent(returnsrgba(0, 0, 0, 0))