Last Updated on : 2024-06-05 03:14:35download
This topic describes the utility methods that are used to convert color values.
hsvToRgb
Convert hue, saturation, value (HSV) color values to red, green, blue (RGB) color values.
Name | Data type | Description | Required |
---|---|---|---|
h | number | The hue of a color. Valid values: 0° to 360° . |
Yes |
s | number | The saturation of a color. Valid values: 0% to 100% . |
Yes |
v | number | The value of a color. Valid values: 0% to 100% . |
Yes |
Name | Data type | Description |
---|---|---|
rgb | { r: number, g: number, b: number} |
The RGB color values. |
import { Utils } from "tuya-panel-kit";
const { hsvToRgb } = Utils.ColorUtils;
hsvToRgb( h, s, v );
// Example:
hsvToRgb(0, 1, 1);
{ r: 255, g: 0, b: 0 }
rgbToHsv
Convert RGB color values to HSV color values.
Name | Data type | Description | Required |
---|---|---|---|
r | number | The red value of a color. Valid values: 0 to 255 . |
Yes |
g | number | The green value of a color. Valid values: 0 to 255 . |
Yes |
b | number | The blue value of a color. Valid values: 0 to 255 . |
Yes |
Name | Data type | Description |
---|---|---|
hsv | { h: number, s: number, v: number} |
The HSV color values. |
import { Utils } from "tuya-panel-kit";
const { rgbToHsv } = Utils.ColorUtils;
rgbToHsv(r, g, b);
// Example:
rgbToHsv(255, 0, 0);
rgbToHsv(128, 1, 0);
{h: 0, s: 1, v: 1}
{h: 0, s: 1, v: 0.5019607843137255}
hex2hsv
Convert hexadecimal color values to HSV color values.
Name | Data type | Description | Required |
---|---|---|---|
hex | string | The hexadecimal color values. | Yes |
Name | Data type | Description |
---|---|---|
hsv | number[] |
The HSV color values. |
import { Utils } from "tuya-panel-kit";
const { color } = Utils.ColorUtils;
color.hex2hsv(hex);
// Example:
color.hex2hsv('#FF00FF');
[ 300, 100, 100 ]
rgb2hex
Convert RGB color values to hexadecimal color values.
Name | Data type | Description | Required |
---|---|---|---|
r | number | The red value of a color. Valid values: 0 to 255 . |
Yes |
g | number | The green value of a color. Valid values: 0 to 255 . |
Yes |
b | number | The blue value of a color. Valid values: 0 to 255 . |
Yes |
Name | Data type | Description |
---|---|---|
hex | string | The hexadecimal color values. |
import { Utils } from "tuya-panel-kit";
const { color } = Utils.ColorUtils;
color.rgb2hex(r, g, b);
// Example:
color.rgb2hex(255, 255, 255);
#FFFFFF
hex2RgbString
Convert hexadecimal color values to red, green, blue, alpha (RGBA) color values.
Name | Data type | Description | Required |
---|---|---|---|
hex | string | The hexadecimal color values. | Yes |
alpha | number | The opacity of a color. | Yes |
Name | Data type | Description |
---|---|---|
rgba | { r: number, g: number, b: number, a: number} |
The red, green, blue, alpha (RGBA) color values. |
import { Utils } from "tuya-panel-kit";
const { color } = Utils.ColorUtils;
color.hex2RgbString(hex, alpha);
// Example:
color.hex2RgbString('#FF00FF', 1);
rgba(255, 0, 255, 1)
hsv2RgbString
Convert HSV color values to RGBA color values.
Name | Data type | Description | Required |
---|---|---|---|
h | number | The hue of a color. Valid values: 0° to 360° . |
Yes |
s | number | The saturation of a color. Valid values: 0% to 100% . |
Yes |
v | number | The value of a color. Valid values: 0% to 100% . |
Yes |
alpha | number | The opacity of a color. | Yes |
Name | Data type | Description |
---|---|---|
rgba | { r: number, g: number, b: number, a: number} |
The red, green, blue, alpha (RGBA) color values. |
import { Utils } from "tuya-panel-kit";
const { color } = Utils.ColorUtils;
color.hsv2RgbString(h, s, v, alpha);
// Example:
color.hex2RgbString(231, 231, 231, 1);
rgba(0, 38, 255, 1)
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback