kernelgpf Posted June 6, 2007 Share Posted June 6, 2007 With PHP, I'm looking for some way to select certain colors depending upon others. Such as if a parent dragon had skin the color #FFFFFF, and the other parent had #018274, how could I find a medium between each color? [the hex code ] Link to comment https://forums.phpfreaks.com/topic/54501-solved-hex-code/ Share on other sites More sharing options...
dbillings Posted June 6, 2007 Share Posted June 6, 2007 RGB color wouldn't do ya? Link to comment https://forums.phpfreaks.com/topic/54501-solved-hex-code/#findComment-269599 Share on other sites More sharing options...
Barand Posted June 6, 2007 Share Posted June 6, 2007 try this <?php $sire = '#FFFFFF'; $dam = '#018274'; $cub = avgColor($sire, $dam); echo "<table border='1'> <tr> <th>Sire</th> <th>Cub</th> <th>Dam</th> </tr> <tr> <td style='color: $cub; background-color: $sire'>$sire</td> <td style='color: black; background-color: $cub'>$cub</td> <td style='color: $cub; background-color: $dam'>$dam</td> </tr> </table> "; function rgb ($color) { $color = hexdec(trim($color, '#')); $r = ($color >> 16) & 0xFF; $g = ($color >> & 0xFF; $b = ($color) & 0xFF; return array ($r, $g, $b); } function avgColor ($a, $b) { $ar1 = rgb ($a); $ar2 = rgb ($b); $res = array(); foreach ($ar1 as $k => $c1) { $c2 = $ar2[$k]; $res[$k] = round(($c1 + $c2)/2); } return vsprintf ('#%02X%02X%02X', $res); } ?> Link to comment https://forums.phpfreaks.com/topic/54501-solved-hex-code/#findComment-269601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.