**/
- $TargetDistance = 32768;
+ // Note: The text distance is actually pre-squared
+ // Background range is from 24-64, all three colors are the same
+ // Text range is from 196 to 255
+ $BackgroundTargetDistance = 12;
+ $BackgroundAdjust = 1;
+ $TextTargetDistance = 65536;
+ $TextAdjust = 0.95;
function IsUnique($Distance, $r, $g, $b, $usedArray)
{
$color[3] = "#000000";
$color[4] = "#000000";
- $used = array(array(0, 0, 0));
- $targetDistance = $TargetDistance;
+ $used = array(0);
+ $targetDistance = $BackgroundTargetDistance;
$Left = array(0, 5, 9, 10, 12);
while (count($Left) > 0) {
// Some background colors
- $r = mt_rand(32,64);
- $g = $r;
- $b = $r;
- if (IsUnique($targetDistance, $r, $g, $b, $used)) {
+ $r = mt_rand(24,64);
+ $unique = true;
+ foreach ($used as $col) {
+ if (abs($r - $col) < $targetDistance)
+ $unique = false;
+ }
+ if ($unique) {
$i = array_shift($Left);
- $color[$i] = sprintf("#%02X%02X%02X",$r,$g,$b);
- $used[] = array($r, $g, $b);
- $targetDistance = $TargetDistance;
+ $color[$i] = sprintf("#%02X%02X%02X",$r,$r, $r);
+ $used[] = $r;
+ $targetDistance = $BackgroundTargetDistance;
} else {
- $targetDistance *= 0.9;
+ $targetDistance -= $BackgroundAdjust;
}
}
}
$Left = array(1, 7, 11, 13, 14, 15);
- $targetDistance = $TargetDistance;
+ $targetDistance = $TextTargetDistance;
while (count($Left) > 0) {
// Text colors -- Try to keep the colors distinct
$cmin = 196;
$i = array_shift($Left);
$color[$i] = sprintf("#%02X%02X%02X",$r,$g,$b);
$used[] = array($r, $g, $b);
- $targetDistance = $TargetDistance;
+ $targetDistance = $TextTargetDistance;
} else {
- $targetDistance *= 0.9;
+ $targetDistance *= $TextAdjust;
}
}