Created
February 6, 2017 08:24
-
-
Save devyfriend/7a41988c34944917e673405551905ef6 to your computer and use it in GitHub Desktop.
generate random color in php and pastel color in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function random_color_1(){ | |
$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'); | |
return '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)]; | |
} | |
function random_color_3(){ | |
return '#'.strtoupper(dechex(rand(0,10000000))); | |
} | |
function random_color_2(){ | |
$spread = 25; | |
$r = 0; $g = 0; $b = 0; | |
for ($row = 0; $row < 100; ++$row) { | |
for($c=0;$c<3;++$c) { | |
$color[$c] = rand(0+$spread,255-$spread); | |
} | |
for($i=0;$i<92;++$i) { | |
$r = rand($color[0]-$spread, $color[0]+$spread); | |
$g = rand($color[1]-$spread, $color[1]+$spread); | |
$b = rand($color[2]-$spread, $color[2]+$spread); | |
} | |
} | |
return "rgb($r,$g,$b)"; | |
} | |
?> | |
<script> | |
var hue = Math.floor(Math.random() * 360); | |
var pastel = 'hsl(' + hue + ', 100%, 87.5%)'; | |
document.body.style.backgroundColor = pastel; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment