I need for a projet to get a color from a value. I explain, I have datas and each data must be represented by a color.
The red color is for the maximum, and the blue for the minimum and the green is for the middle value. A kind of heatmap.
So, I need to have a function returning the right color.
I tried something like this :
function datatocolor($min, $max, $value)
{
$half = (($min + $max) / 2);
if ($value > $half)
{
$r = (255 * ($value+$min-$half)) / $half;
$g = 255 - $r;
$b = 0;
}
else {
$b = (255 * ($half-$value+$min)) / $half;
$g = 255 - $b;
$r = 0;
}
$color = array(intval($r), intval($g), intval($b));
return $color;
}
But, I get red and blue, and never green ... I tried a lot of operations, I must be stupid but I don't find the right operation ... Thanks in advance for your help !