RGB 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() → {RGB}
- css_to_rgb(css_red, css_green, css_blue, destopt) → {RGB}
- from_values(r, g, b) → {RGB}
- rgb_to_css(rgb) → {Array.<number>}
- rgb_to_css_hex(rgb) → {string}
- set(r, g, b, dest) → {RGB}
Detailed Description
Methods
create() → {RGB}
Creates a new empty RGB vector representing black color.
Returns:
A new RGB vector.
- Type
- RGB
- Source:
Example
var m_rgb = require("rgb");
var new_color = m_rgb.create();
css_to_rgb(css_red, css_green, css_blue, destopt) → {RGB}
Convert CSS color components to RGB.
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). | ||
dest |
RGB |
<optional> |
rgb.create() | Destination RGB vector. |
Returns:
Destination RGB vector.
- Type
- RGB
- Source:
Example
var m_rgb = require("rgb");
// #808080 or rgb(128, 128, 128) converted to [0.219, 0.219, 0.219]
var rgb_color = m_rgb.css_to_rgb(128, 128, 128);
from_values(r, g, b) → {RGB}
Creates a new RGB vector initialized with the given values.
Parameters:
Name | Type | Description |
---|---|---|
r |
number | Red component. |
g |
number | Green component. |
b |
number | Blue component. |
Returns:
A new RGB vector.
- Type
- RGB
- Source:
Example
var m_rgb = require("rgb");
var new_color = m_rgb.from_values(0.5, 0.5, 0.5);
rgb_to_css(rgb) → {Array.<number>}
Convert RGB color components to CSS color.
Parameters:
Name | Type | Description |
---|---|---|
rgb |
RGB | RGB color vector. |
Returns:
Array with CSS colors.
- Type
- Array.<number>
- Source:
Example
var m_rgb = require("rgb");
var rgb_color = m_rgb.from_values(0.219, 0.219, 0.219);
// [0.219, 0.219, 0.219] converted to [128, 128, 128]
var color = m_rgb.rgb_to_css(rgb_color);
rgb_to_css_hex(rgb) → {string}
Convert RGB color components to CSS color hex string.
Parameters:
Name | Type | Description |
---|---|---|
rgb |
RGB | RGB color vector. |
Returns:
CSS color hex string.
- Type
- string
- Source:
Example
var m_rgb = require("rgb");
var rgb_color = m_rgb.from_values(0.219, 0.219, 0.219);
// [0.219, 0.219, 0.219] converted to "#808080"
var hex_color = m_rgb.rgb_to_css_hex(rgb_color);
set(r, g, b, dest) → {RGB}
Set the components of RGB vector to the given values.
Parameters:
Name | Type | Description |
---|---|---|
r |
number | Red component. |
g |
number | Green component. |
b |
number | Blue component. |
dest |
RGB | Destination RGB vector. |
Returns:
Destination RGB vector.
- Type
- RGB
- Source:
Example
var m_rgb = require("rgb");
var new_color = new Float32Array(3);
m_rgb.set(0.7, 0.5, 0.1, new_color);