Forum Moderators: coopster

Message Too Old, No Replies

Degrees of colors

How to do?

         

adni18

3:22 am on Feb 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

What I'm trying to do is come up with a script which will, if you will, combine two colors to a certain degree. For instance, let's say I have the colors red and blue, and I want to make purple. The degree would be 50% and the script would combine the two colors so that there is 50% of red and 50% of blue, resulting in purple.

How would I go about doing this?

Thanks,
Philip

adni18

4:11 am on Feb 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nevermind, I think I got it :)


function twol($num)
{
if(strlen($num) == 1)
{
return "0".$num;
}
else
{
return $num;
}
}

function combine($from, $to, $degr)
{

$sum=array(

(hexdec($from[0])*((100-$degr)/100))+(hexdec($to[0])*($degr/100)),
(hexdec($from[1])*((100-$degr)/100))+(hexdec($to[1])*($degr/100)),
(hexdec($from[2])*((100-$degr)/100))+(hexdec($to[2])*($degr/100))

);

return twol(dechex($sum[0])).twol(dechex($sum[1])).twol(dechex($sum[2]));

}

combine(array("FF","00","00"), array("00","00","FF"), 50)