I start with a base color and need to get two other colors based on that one: a 50% lighter and a 50% darker.
From the hex value of the base color, I run the following for each R, G, B channel:
$hexcolor="#FFCC00"; //the base color
$rgb["r"]=substr($hexcolor, 1, 2); //hex value for red channel
$rgb["g"]=substr($hexcolor, 3, 2); //hex value for green channel
$rgb["b"]=substr($hexcolor, 5, 2); //hex value for blue channel
$light="#";
$dark="#";
foreach($rgb as $channel=>$hex_value)
{
$hex_value=hexdec($hex_value); //convert hex to dec to do maths
$light.=dechex((255-$hex_value)/2+$hex_value);
$dark.=dechex($hex_value/2);
}
This works OK, but some colors(especially the darker ones) spit out undesired results: dark blue=>red (with certain values).
Are there more accurate maths for acheiving this?