Ask a Question related to PHP Development, Design and Development.
-
Bill Parker #1
random text & background colors?
Hi
Is there a way to generate colour hex strings that are guaranteed to be dark
and thus good as random-generated text colours?
something like
-------------------
srand((double)microtime()*1000000);
function tc() {
$frag = range(0,6);
$text = "#";
for ($i = 1; $i <= 6; $i++) {
$text = $text . $frag[mt_rand(0, count($frag)-1)];
}
return $text;
}
$text = tc();
--------------------
is what I have in mind.... but I really don't know how the hex codes for rgb
realte to "darkness"
And while I'm on the subject, whats the converse (for pale colours, for
backgrounds) look like?
I'm sure someone will have done this somewhere before...
Cheers
Bill
Bill Parker Guest
-
Background colors
Jumping into the thread late... When a projector is set to "full screen" the area outside of the stage area is filled with the movie backgrounnd... -
Making PDF w/o web page background colors?
When making PDF from web pages, is there a way to have Acrobat ignore the background color? If I'm only after the text & images, when printed,... -
Background Colors??
Is it possible to customize cell and table background colors? I've got the eyedropper thing down - but is there a way to enter the desired color,... -
random/rotating background patterns
Client wants random rotating background patterns - so each time you reload the page, or click to another page you will see a different background... -
Change the edit Field background color in alternating portal colors
Sure, Marcel, please look at www.tekstotaal.com/c.fmp.portal.blackening.html -- Met vriendelijke groet / Mit freundlichen Grüßen / With kind... -
Geoff Berrow #2
Re: random text & background colors?
Message-ID: <bdm774$2jj$1@news-reader2.wanadoo.fr> from Bill Parker
contained the following:
>is what I have in mind.... but I really don't know how the hex codes for rgb
>realte to "darkness"
You have six hexadecimal values - two for red, two for green, two for blue.
The two values multiplied together give a range of 0-255 for each colour
A hex number is a number between 0 and 15 which is displayed as the numbers
0-9 and the letters A-F. Hence A = 10, B=11 and so on. Light colours have
higher values, and hence #000000 is black and #FFFFFF is white. So a mid
grey is between #777777 and #888888.
I assume that your definition of a dark colour would be any colour that was
darker than this mid point. (though this is clearly going to be subjective)
From the above you can see that any colour whose hex values are less than
or equal to 7 is guaranteed to be a dark colour and any colour where values
are greater than or equal to 8 is light. Also, any colour where the
/average/ of the hex values is less than 7 is dark also. So #000ccc has an
average of (0+0+0+12+12+12)/6 which equals 6 and so is 'dark'. Similarly,
#00FFFF has an average of 10 and is hence 'light'.
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
Geoff Berrow Guest
-
Bill Parker #3
Re: random text & background colors?
Thanks for the detailed explanation. The bit about taking an average of the
three values was especially informative to me.
If anyone else is interested, I've put together this very simple function by
way of an example (I'm using VERY conservative values for "lightness" and
"darkness")
Bill
-----------
function colour($tint) {
$frag = range(0,255);
$red = "";
$green = "";
$blue = "";
for (;;) {
$red = $frag[mt_rand(0, count($frag)-1)];
$green = $frag[mt_rand(0, count($frag)-1)];
$blue = $frag[mt_rand(0, count($frag)-1)];
switch ($tint) {
case 'light':
if (($red + $green + $blue / 3) >= 200) break 2;
break;
case 'dark' :
default:
if (($red + $green + $blue / 3) <= 50) break 2;
break;
}
}
return sprintf("#%02s%02s%02s", dechex($red), dechex($green),
dechex($blue));
}
$background = colour('light');
$text = colour('dark');
--------------
Bill Parker Guest



Reply With Quote

