Skip to main content

RGBA Class

The RGBA 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
Create from normalized RGBA values
number
required
Red component (0.0 to 1.0)
number
required
Green component (0.0 to 1.0)
number
required
Blue component (0.0 to 1.0)
number
Alpha component (0.0 to 1.0). Default: 1.0
function
Create from integer RGBA values (0-255)
number
required
Red component (0 to 255)
number
required
Green component (0 to 255)
number
required
Blue component (0 to 255)
number
Alpha component (0 to 255). Default: 255
function
Create from a hex color string
string
required
Hex color: "#RGB", "#RRGGBB", "#RGBA", or "#RRGGBBAA" (with or without #)
Returns magenta (#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 values
Returns an array of integers (0-255).
function
Convert to string representation
Returns a string like "rgba(0.50, 0.75, 1.00, 1.00)".
function
Check equality with another color
Returns true if all components are equal.
function
Map a function over all components
Example:

Color Utilities

Hex Conversion

function
Convert hex string to RGBA
Supports 3, 4, 6, and 8 character hex codes (with or without #).
function
Convert RGBA to hex string
Returns 6-character hex for opaque colors, 8-character for transparent.

Color Space Conversion

function
Convert HSV to RGB
number
required
Hue (0 to 360)
number
required
Saturation (0.0 to 1.0)
number
required
Value/Brightness (0.0 to 1.0)
Always returns opaque color (alpha = 1.0).

Color Parsing

function
Parse a color from string or RGBA object
string | RGBA
required
Color to parse
Supports:
  • Hex colors: "#FF0000", "#F00", etc.
  • CSS color names: "red", "blue", "transparent", etc.
  • Existing RGBA objects (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 (returns rgba(0, 0, 0, 0))

Examples

Creating Colors

Using parseColor

Color Manipulation

HSV Color Generation

Using with FrameBuffer

Type Definitions