ポイント |
r = g = b = 0;
if (s < 0) s = 0;
if (s > 1) s = 1;
if (l < 0) l = 0;
if (l > 1) l = 1;
h = h % 360;
if (h < 0) h = h + 360;
if (l <= 0.5)
{
cmin = l * ( 1 - s );
cmax = 2 * l - cmin;
}else{
cmax = l * ( 1 - s ) + s;
cmin = 2 * l - cmax;
}
r = h2v(h+120,cmin,cmax);
g = h2v(h,cmin,cmax);
b = h2v(h-120,cmin,cmax);
function h2v(hh,min,max)
{
hh = hh % 360;
if (hh < 0) hh = hh + 360;
if (hh < 60) return min + (max - min) * hh / 60;
if (hh >= 60 && hh < 180) return max;
if (hh >=180 && hh < 240) return min+(max-min)*(240-hh)/60;
return min;
}
|