Module: rgb

RGB colors API. Colors in Blend4Web are always stored in linear space, for more info check documentation.
Source:

Summary

Methods

Detailed Description

Methods

create() → {RGB}

Creates a new empty RGB vector representing black color.
Returns:
A new RGB vector.
Type
RGB
Source:

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:

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: