eh sto ti je php manual, user comment frajer napravio bas ono sto mi treba :)
Code:
daevid at daevid dot com
18-Mar-2004 05:59
Here's my version of a red->yellow->green gradient:
<?php
function colorMeter($percent, $invert = false)
{
//$percent is in the range 0.0 <= percent <= 1.0
// integers are assumed to be 0% - 100%
// and are converted to a float 0.0 - 1.0
// 0.0 = red, 0.5 = yellow, 1.0 = green
//$invert will make the color scale reversed
// 0.0 = green, 0.5 = yellow, 1.0 = red
//convert (int)% values to (float)
if (is_int($percent)) $percent = $percent * 0.01;
$R = min((2.0 * (1.0-$percent)), 1.0) * 255.0;
$G = min((2.0 * $percent), 1.0) * 255.0;
$B = 0.0;
return (($invert) ?
sprintf("%02X%02X%02X",$G,$R,$B)
: sprintf("%02X%02X%02X",$R,$G,$B));
} //colorMeter
?>
and use it like this:
<TABLE BORDER=1 WIDTH="300">
<?php
for ($i = 0.0; $i <= 1.0; $i += 0.10)
{
$RGB = colorMeter($i);
print "<TR><TD BGCOLOR='".$RGB."'>".$i."</TD><TD>
<PRE>".$RGB."</PRE></TD></TR>\n";
}
?>
</TABLE>
<P>
<TABLE BORDER=1 WIDTH="300">
<?php
for ($i = 0; $i <= 100; $i += 10)
{
$RGB = colorMeter(intval($i), true);
print "<TR><TD BGCOLOR='".$RGB."'>".$i."</TD><TD>
<PRE>".$RGB."</PRE></TD></TR>\n";
}
?>
</TABLE>
http://www.php.net/dechex
dobro ovo prebaciti u matrice je streight forward