All pastes #706051 Raw Edit

Untitled

public php v1 · immutable
#706051 ·published 2007-09-21 16:18 UTC
rendered paste body
<?php$original = '3244ea';$new = 'abcd34';$increment = 10;$values = array($original, $new);foreach(MultiColorFade($values, $increment) as $hex)	echo'<div style="display:block; border:1px solid #000; width:100px; height: 30px; background:#' . $hex . '">#' . $hex . '</div>'; 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;}?>