From 8c933a3232fe74dd621e8c10b7be4fc7cc3b39b8 Mon Sep 17 00:00:00 2001 From: fidian Date: Fri, 4 Jan 2002 14:47:31 +0000 Subject: [PATCH] Minor changes to make the colors more separate from each other without entering infinite loops. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2097 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- themes/darkness.php | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/themes/darkness.php b/themes/darkness.php index c8db65e4..d0b9cfa1 100755 --- a/themes/darkness.php +++ b/themes/darkness.php @@ -6,7 +6,13 @@ **/ - $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) { @@ -64,21 +70,24 @@ $squirrelmail_plugin_hooks['generic_header']['theme_darkness'] = $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; } } @@ -101,7 +110,7 @@ $squirrelmail_plugin_hooks['generic_header']['theme_darkness'] = } $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; @@ -116,9 +125,9 @@ $squirrelmail_plugin_hooks['generic_header']['theme_darkness'] = $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; } } -- 2.25.1