HsvToRgb
Материал из MajorDoMo инфо
Описание
hsvToRgb($h, $s, $v); --
Примеры запросов
$color = gg('Object.Value'); $HSV=$color;
$H=hexdec(substr($HSV,0,4)); $S=hexdec(substr($HSV,4,4)); $V=hexdec(substr($HSV,8,4));
//$H = $H/360;
//$S = $S/1000;
//$V = $V/1000;
$S = $S/10;
$V = $V/10;
//echo '
-------
';
//echo 'H: ';
//echo $H;
//echo '
-------
';
//echo 'S: ';
//echo $S;
//echo '
-------
';
//echo 'V: ';
//echo $V;
//echo '
-------
';
var_dump(hsv2rgb($H, $S, $V));
function hsv2rgb($hue,$sat,$val) { $rgb = array(0,0,0); //calc rgb for 100% SV, go +1 for BR-range for($i=0;$i<4;$i++) { if (abs($hue - $i*120)<120) { $distance = max(60,abs($hue - $i*120)); $rgb[$i % 3] = 1 - (($distance-60) / 60); } } //desaturate by increasing lower levels $max = max($rgb); $factor = 255 * ($val/100); for($i=0;$i<3;$i++) { //use distance between 0 and max (1) and multiply with value $rgb[$i] = round(($rgb[$i] + ($max - $rgb[$i]) * (1 - $sat/100)) * $factor); } $rgb['html'] = sprintf('#%02X%02X%02X', $rgb[0], $rgb[1], $rgb[2]); echo "Хуе: $hue
\r\n"; echo "Сат: $sat
\r\n"; echo "Вал: $val
\r\n"; echo $rgb; sg('Object.Value', sprintf( '#%02X%02X%02X', $rgb[0], $rgb[1], $rgb[2])); return $rgb;
}