Colors darker than

SpaceshipSpaceship
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Watch

Tree

Established Member
Impact
9
Is there a way in PHP to randomly select all colors darker than, say, #696969?

I have a randomColor function already:

PHP:
function randomColor()
{
	return str_pad(dechex(mt_rand(0, 16777215)), 6, '0', STR_PAD_LEFT);
}

I just don't know where #696969 stops in base 10.

:santa:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Something like this maybe?

PHP:
function darker_color($color, $dif=20){
$color = str_replace('#', '', $color);
if (strlen($color) != 6){ return '000000'; }
$rgb = '';
for ($x=0;$x<3;$x++){
$c = hexdec(substr($color,(2*$x),2)) - $dif;
$c = ($c < 0) ? 0 : dechex($c);
$rgb .= (strlen($c) < 2) ? '0'.$c : $c;
}
return '#'.$rgb;
}

Than use something like
PHP:
for ($x=1; $x < 20; $x++){
// Start color:
$c = darker_color('#FF481D', ($x*3));

print "<div style='background-color: $c; color: $c; font-size: 50%; padding: 0px;'>.</div>\n";
}
To print it.. Where as the number of required darker amounts is 20..

Or what ever you need..

- Steve
 
Last edited:
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
URLs.com
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back