note 18951 added to function.dechex
| From: | kristoffer at caveo dot se | Date: | Mon, 11 Feb 2002 10:39:03 +0000 |
| Subject: | note 18951 added to function.dechex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26466@lists.php.net to get a copy of this message | ||
Heres a example of dec to html hex gradient. Have fun :)
//Amount of gradients
$l = 20;
//Start color
$start[0] = "255"; //red
$start[1] = "0"; //green
$start[2] = "255"; //blue
//End color
$end[0] = "255"; //red
$end[1] = "255"; //green
$end[2] = "255"; //blue
for ($t = 1; $t < $l;) {
$x = $x * $t;
for ($i = 0; $i < 3;) {
$buffer[$i] = $start[$i] - $end[$i];
$buffer[$i] = floor($buffer[$i] / $l);
$rgb[$i] = $start[$i] - ($buffer[$i] * $t);
if ($rgb[$i] > 255) {
$rgb[$i] = 255;
}
$rgb[$i] = dechex($rgb[$i]);
$rgb[$i] = strtoupper($rgb[$i]);
if (strlen($rgb[$i]) < 2) {
$rgb[$i] = "0$rgb[$i]";
}
$i++;
}
$color = "$rgb[0]$rgb[1]$rgb[2]";
echo "$color";
$t++;
}
?>
--
http://www.php.net/manual/en/function.dechex.php
http://master.php.net/manage/user-notes.php?action=edit+18951
http://master.php.net/manage/user-notes.php?action=delete+18951
http://master.php.net/manage/user-notes.php?action=reject+18951