首页 > 代码库 > 给出两个颜色,计算中间颜色返回数组

给出两个颜色,计算中间颜色返回数组


$start_color = array(255, 220, 220);
$end_color = array(255, 80, 80);
$n = count($data);
$colors = array();
for ($i=0; $i<$n;$i++) {
$a = $start_color[0] + round(($end_color[0]-$start_color[0])/$n*$i);
$b = $start_color[1] + round(($end_color[1]-$start_color[1])/$n*$i);
$c = $start_color[2] + round(($end_color[2]-$start_color[2])/$n*$i);
$colors[] = array(
$a, $b, $c
);
}
foreach($colors as &$v){
$v = ‘#‘.dechex($v[0]).dechex($v[1]).dechex($v[2]);
}
unset($v);

$this->ajax_response(AJAX_SUCCESS, array(
‘color‘ => $colors
));

给出两个颜色,计算中间颜色返回数组