RGB_Farbastic
(custom)
<script type="text/javascript" src="../farbtastic/farbtastic.js"></script>
<link rel="stylesheet" href="../farbtastic/farbtastic.css" type="text/css" />
<div id="colorpicker" style="margin: 0 auto;"></div>
<script type="text/javascript">
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function calc(r,g,b)
{
if( r=="" ) r=0;
if( g=="" ) g=0;
if( b=="" ) b=0;
r = parseFloat(r);
g = parseFloat(g);
b = parseFloat(b);
if( r<0 ) r=0;
if( g<0 ) g=0;
if( b<0 ) b=0;
if( r>255 ) r=255;
if( g>255 ) g=255;
if( b>255 ) b=255;
hex = r*65536+g*256+b;
hex = hex.toString(16,6);
len = hex.length;
if( len<6 )
for(i=0; i<6-len; i++)
hex = '0'+hex;
r/=255;
g/=255;
b/=255;
M = Math.max(r,g,b);
m = Math.min(r,g,b);
C = M-m;
if( C==0 ) h=0;
else if( M==r ) h=((g-b)/C)%6;
else if( M==g ) h=(b-r)/C+2;
else h=(r-g)/C+4;
h*=60;
if( h<0 ) h+=360;
v = M;
if( C==0 )
s = 0;
else
s = C/v;
s*=100;
v*=100;
hvalue = h.toFixed(0);
svalue = s.toFixed(1);
vvalue = v.toFixed(1);
}
$('#colorpicker').farbtastic( function (color) {
r = HexToR(color);
g = HexToG(color);
b = HexToB(color);
ColorHEX = cutHex(color);
calc(r,g,b);
$.get("/objects/?object=MEGA&op=set&p=Red&v="+r);
$.get("/objects/?object=MEGA&op=set&p=Green&v="+g);
$.get("/objects/?object=MEGA&op=set&p=Blue&v="+b);
$.get("/objects/?object=MEGA&op=set&p=Hue&v="+hvalue);
$.get("/objects/?object=MEGA&op=set&p=Saturation&v="+svalue);
$.get("/objects/?object=MEGA&op=set&p=Value&v="+vvalue);
$.get("/objects/?object=MEGA&op=m&m=turnOn");
});
</script>