Here’s a RGB to HSB function that works in Nashorn:
function hex_to_hsb(hex) {
var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
if (!rgb) return '';
var r = parseInt(rgb[1], 16) / 255, g = parseInt(rgb[2], 16) / 255, b = parseInt(rgb[3], 16) / 255;
var v = Math.max(r, g, b), n = v - Math.min(r, g, b);
var h = n === 0 ? 0 : n && v === r ? (g - b) / n : v === g ? 2 + (b - r) / n : 4 + (r - g) / n;
return [60 * (h < 0 ? h + 6 : h), v && (n / v) * 100, v * 100].join(',');
}
print(hex_to_hsb('#ff0000'));
Taken from framework7/utils.js at ce7a2dc21b29a05d6c782bd53a4155f542867d9c · framework7io/framework7 · GitHub (colorHexToRgb) and RGBToHSB - 30 seconds of code.