User:Tpatru/vector.js

16; $red_2 = ($color_2 & 0xff0000) >16; $grn_1 = ($color_1 & 0xff00) >8; $grn_2 = ($color_2 & 0xff00) >8; $blu_1 = ($color_1 & 0xff); $blu_2 = ($color_2 & 0xff); return (abs($red_1 - $red_2) + abs($grn_1 - $grn_2) + abs($blu_1 - $blu_2)); }

$source = 0xff00ff; $seeker = $marker = 0xffffff; $target = 500; $best_contrast = 0; $best_color = 0;

$contrast = color_contrast($source, $seeker); while(($contrast < $target) and ($marker != 0)) { $marker = intval($marker / 2); if($contrast $target) { $seeker -= $marker; } else if($contrast < $target) { $seeker += $marker; } $contrast = color_contrast($source, $seeker); if($contrast $best_contrast) { $best_contrast = $contrast; $best_color = $seeker; } } echo("\n Color: " . dechex($best_color) . " Contrast $best_contrast"); ?>