Setting HSV colors with JavaScript
1. In Global JavaScript
function ggbOnInit() {}
// Sets HSV colors instead of RGB
// @param h, s, v
// @return r, g, b normalized values for the HSV scheme color
function setHSV(h, s, v) {
var r, g, b, i, f, p, q, t;
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
r = v, g = t, b = p;
break;
case 1:
r = q, g = v, b = p;
break;
case 2:
r = p, g = v, b = t;
break;
case 3:
r = p, g = q, b = v;
break;
case 4:
r = t, g = p, b = v;
break;
case 5:
r = v, g = p, b = q;
break;
}
var n = 255;
return [Math.round(r * n) / n, Math.round(g * n) / n, Math.round(b * n) / n];
}
2. Create button "SetColors" with JavaScript
var h = ggbApplet.getValue('h'); // Get value "hue"
var s = ggbApplet.getValue('s'); // Get value "sat"
var v = ggbApplet.getValue('v'); // Get value "val"
var colors = setHSV(h, s, v); // Store hsv colors
// Now set color in RGB
ggbApplet.evalCommand("SetValue(r, " + colors[0] + ")");
ggbApplet.evalCommand("SetValue(g, " + colors[1] + ")");
ggbApplet.evalCommand("SetValue(b, " + colors[2] + ")");
3. Update values in sliders h, s and v
RunClickScript( SetColors )