fb:porticula NoPaste
[php] defektes hsv2rgb
Uploader: | PMedia |
Datum/Zeit: | 08.09.2007 20:25:40 |
function hsv2rgb($h, $s, $v)
{
$colorRGB = "#";
$h = (($h / 256) * 360);
$s = $s / 256;
$v = $v / 256;
$hi = round(h/60);
$f = (h%60)/60;
$p = $v*(1-$s);
$q = $v*(1-($s*$f));
$t = $v*(1-($s*(1-$f)));
if ($hi == 0) { $r = $v; $g = $t; $b = p; }
if ($hi == 1) { $r = $q; $g = $v; $b = p; }
if ($hi == 2) { $r = $p; $g = $v; $b = t; }
if ($hi == 3) { $r = $p; $g = $q; $b = v; }
if ($hi == 4) { $r = $t; $g = $p; $b = v; }
if ($hi == 5) { $r = $v; $g = $p; $b = q; }
if (strlen(dechex($r)) == 1) { $colorRGB .= "0" . dechex($r); }
if (strlen(dechex($r)) == 2) { $colorRGB .= dechex($r); }
if (strlen(dechex($g)) == 1) { $colorRGB .= "0" . dechex($g); }
if (strlen(dechex($g)) == 2) { $colorRGB .= dechex($g); }
if (strlen(dechex($b)) == 1) { $colorRGB .= "0" . dechex($b); }
if (strlen(dechex($b)) == 2) { $colorRGB .= dechex($b); }
$colorRGB .= ";";
return $colorRGB;
}