note 66410 deleted from function.dechex by bjori

From: Date: Sun, 28 May 2006 19:28:45 +0000
Subject: note 66410 deleted from function.dechex by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-112461@lists.php.net to get a copy of this message
Note Submitter: repley at freemail dot it ---- 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(); for($pointer = 0; $pointer < $tot-1 ; $pointer++) { $hexstart = $hex_array[$pointer]; $hexend = $hex_array[$pointer + 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']) / ($steps - 1); $step['g'] = ($start['g'] - $end['g']) / ($steps - 1); $step['b'] = ($start['b'] - $end['b']) / ($steps - 1); for($i = 0; $i < $steps-1; $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[] = array_pop($hex_array); return $gradient; } //end MultiColorFade() //start test $hex_array = array("FF0000","FFFF00","00FF00","0000FF"); $a = MultiColorFade($hex_array, 18); $tot = count($a); $table = '<table border=1 width="300">' . "\\n"; for ($i = 0; $i < $tot; $i++){ $table .= ' <tr><td bgcolor="'.$a[$i].'">'.$i.'</td><td><pre>'.$a[$i].'</pre></td></tr>' . "\\n"; } $table .= '</table>'; echo $table; //end test ?> Repley.

« previous php.notes (#112461) next »