RGBA colors API.
To match standard Blender behavior colors in Blend4Web are always stored in linear space, for more info check the documentation.
- Source:
Summary
Methods
- create() → {RGBA}
- css_to_rgba(css_red, css_green, css_blue, css_alpha, destopt) → {RGBA}
- from_values(r, g, b, a) → {RGBA}
- rgba_to_css(rgba) → {Array.<number>}
- set(r, g, b, a, dest) → {RGBA}
Detailed Description
Methods
create() → {RGBA}
Creates a new empty RGB vector representing black opaque color.
Returns:
A new RGBA vector.
- Type
- RGBA
- Source:
Example
var m_rgba = require("rgba");
var new_rgba_color = m_rgba.create();
css_to_rgba(css_red, css_green, css_blue, css_alpha, destopt) → {RGBA}
Convert CSS color components to RGBA.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
css_red |
number | CSS color red component (0-255). | ||
css_green |
number | CSS color green component (0-255). | ||
css_blue |
number | CSS color blue component (0-255). | ||
css_alpha |
number | CSS alpha component (0-1). | ||
dest |
RGBA |
<optional> |
rgba.create() | Destination RGB vector. |
Returns:
Destination RGB vector.
- Type
- RGBA
- Source:
Example
var m_rgba = require("rgba");
// rgba(128, 128, 128, 0.5) converted to [0.219, 0.219, 0.219, 0.5]
var rgba_color = m_rgba.css_to_rgba(128, 128, 128, 0.5);
from_values(r, g, b, a) → {RGBA}
Creates a new RGBA vector initialized with the given values.
Parameters:
Name | Type | Description |
---|---|---|
r |
number | Red component. |
g |
number | Green component. |
b |
number | Blue component. |
a |
number | Alpha component. |
Returns:
A new RGBA vector.
- Type
- RGBA
- Source:
Example
var m_rgba = require("rgba");
var new_rgba_color = m_rgba.from_values(0.5, 0.5, 0.5, 0.5);
rgba_to_css(rgba) → {Array.<number>}
Convert RGBA color components to CSS color.
Parameters:
Name | Type | Description |
---|---|---|
rgba |
RGBA | RGBA color vector. |
Returns:
Array with CSS colors.
- Type
- Array.<number>
- Source:
Example
var m_rgba = require("rgba");
var rgba_color = m_rgba.from_values(0.219, 0.219, 0.219, 0.5);
// [0.219, 0.219, 0.219, 0.5] converted to [128, 128, 128, 0.5]
var color = m_rgba.rgba_to_css(rgba_color);
set(r, g, b, a, dest) → {RGBA}
Set the components of RGBA vector to the given values.
Parameters:
Name | Type | Description |
---|---|---|
r |
number | Red component. |
g |
number | Green component. |
b |
number | Blue component. |
a |
number | Alpha component. |
dest |
RGBA | Destination RGBA vector. |
Returns:
Destination RGBA vector.
- Type
- RGBA
- Source:
Example
var m_rgba = require("rgba");
var new_rgba_color = new Float32Array(4);
m_rgba.set(0.1, 0.5, 0.3, 1.0, new_rgba_color);