note 66780 added to function.hexdec
| From: | repleyatfreemaildotit at osu1 dot php dot net | Date: | Mon, 29 May 2006 01:55:32 +0000 |
| Subject: | note 66780 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-112476@lists.php.net to get a copy of this message | ||
From color to color to ...... to color with fade effect. Good for dynamic bar chart.
<?php
//MultiColorFade(array hex-colors, int steps)
function MultiColorFade($hex_array, $steps) {
$tot = count($hex_array);
$gradient = array();
$fixend = 2;
$passages = $tot-1;
$stepsforpassage = floor($steps/$passages);
$stepsremain = $steps - ($stepsforpassage*$passages);
for($pointer = 0; $pointer < $tot-1 ; $pointer++) {
$hexstart = $hex_array[$pointer];
$hexend = $hex_array[$pointer + 1];
if($stepsremain > 0){
if($stepsremain--){
$stepsforthis = $stepsforpassage + 1;
}
}else{
$stepsforthis = $stepsforpassage;
}
if($pointer > 0){
$fixend = 1;
}
$start['r'] = hexdec(substr($hexstart, 0, 2));
$start['g'] = hexdec(substr($hexstart, 2, 2));
$start['b'] = hexdec(substr($hexstart, 4, 2));
$end['r'] = hexdec(substr($hexend, 0, 2));
$end['g'] = hexdec(substr($hexend, 2, 2));
$end['b'] = hexdec(substr($hexend, 4, 2));
$step['r'] = ($start['r'] - $end['r']) / ($stepsforthis);
$step['g'] = ($start['g'] - $end['g']) / ($stepsforthis);
$step['b'] = ($start['b'] - $end['b']) / ($stepsforthis);
for($i = 0; $i <= $stepsforthis-$fixend; $i++) {
$rgb['r'] = floor($start['r'] - ($step['r'] * $i));
$rgb['g'] = floor($start['g'] - ($step['g'] * $i));
$rgb['b'] = floor($start['b'] - ($step['b'] * $i));
$hex['r'] = sprintf('%02x', ($rgb['r']));
$hex['g'] = sprintf('%02x', ($rgb['g']));
$hex['b'] = sprintf('%02x', ($rgb['b']));
$gradient[] = strtoupper(implode(NULL, $hex));
}
}
$gradient[] = $hex_array[$tot-1];
return $gradient;
}
//end MultiColorFade()
//start test
$multi_hex_array = array();
$multi_hex_array[] = array('FF0000','FFFF00');
$multi_hex_array[] = array('FF0000','FFFF00','00FF00');
$multi_hex_array[] =
array('FF0000','FFFF00','00FF00','00FFFF');
$multi_hex_array[] =
array('FF0000','FFFF00','00FF00','00FFFF','0000FF');
$multi_hex_array[] =
array('FF0000','FFFF00','00FF00','00FFFF','0000FF','000000');
$multi_hex_array[] =
array('FF0000','FFFF00','00FF00','00FFFF','0000FF','000000','FFFFFF');
foreach($multi_hex_array as $hex_array){
$totcolors = count($hex_array);
$steps = 44;
$a = MultiColorFade($hex_array, $steps);
$tot = count($a);
$table = '<table border=1 width="300">' . "\n";
for ($i = 0; $i < $tot; $i++){
$table .= ' <tr><td bgcolor="' . $a[$i] . '">' .
($i+1) .'</td><td><pre>' . $a[$i] .
'</pre></td></tr>' . "\n";
}
$table .= '</table><br /><br />';
echo '<br />Demanded steps = ' . $steps . '<br />';
echo 'Returned steps = ' . $tot;
if($steps == $tot){
echo '<br />OK.' . $steps . ' = ' . $tot . '<br
/>';
}else{
echo '<br /><span style="color:#FF0000">FAILED! Demanded steps and
returned steps are NOT equal!: ' . $steps . ' != ' . $tot . '</span><br
/>';
}
echo $table;
}
//end test
?>
Repley.
----
Server IP: 213.92.11.19
Probable Submitter: 84.223.156.155
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit -- http://master.php.net/note/edit/66780
Del: integrated -- http://master.php.net/note/delete/66780/integrated
Del: useless -- http://master.php.net/note/delete/66780/useless
Del: bad code -- http://master.php.net/note/delete/66780/bad+code
Del: spam -- http://master.php.net/note/delete/66780/spam
Del: non-english -- http://master.php.net/note/delete/66780/non-english
Del: in docs -- http://master.php.net/note/delete/66780/in+docs
Del: other reasons-- http://master.php.net/note/delete/66780
Reject -- http://master.php.net/note/reject/66780
Search -- http://master.php.net/manage/user-notes.php