|
一个例子说明如何RGB颜色转换为使用Tizen2.3 HSV颜色。
- var rgbToHsv = function(rgb) {
- var r = rgb[0];
- var g = rgb[1];
- var b = rgb[2];
- r /= 255, g /= 255, b /= 255;
- var max = Math.max(r, g, b),
- min = Math.min(r, g, b);
- var h, s, v = max;
- var d = max - min;
- s = max === 0 ? 0 : d / max;
- if (max == min) {
- h = 0;
- } else {
- switch (max) {
- case r:
- h = (g - b) / d + (g < b ? 6 : 0);
- break;
- case g:
- h = (b - r) / d + 2;
- break;
- case b:
- h = (r - g) / d + 4;
- break;
- }
- h /= 6;
- }
- return [h * 360, s * 100, v * 100];
- };
- rgbToHsv([255, 255, 0]);
复制代码
|
|