Réponse acceptée !
Hello,
Le plus facile il me semble c'est de généréer des couleurs aléatoires a partir de RGB (0 à 255) car tu n'auras qu'a utiliser des
rand.
Après une petite fonction pour convertir le rgb en hexa.
dechex te convertis tes nombre int en hexa et sinon il y a une petite gestion d'erreur.
Voilà si tu ne comprends pas la source, dis moi.
Code PHP :
<?php
function rgb2hexa($r, $g=-1, $b=-1)
{
if (is_array($r) && sizeof($r) == 3)
list($r, $g, $b) = $r;
$r = intval($r); $g = intval($g);
$b = intval($b);
$r = dechex($r<0?0:($r>255?255:$r));
$g = dechex($g<0?0:($g>255?255:$g));
$b = dechex($b<0?0:($b>255?255:$b));
$color = (strlen($r) < 2?'0':'').$r;
$color .= (strlen($g) < 2?'0':'').$g;
$color .= (strlen($b) < 2?'0':'').$b;
return '#'.$color;
}
$macouleur = rgb2hexa(rand(0, 255), rand(0, 255), rand(0, 255));
?>
_________________________________
Min iPomme