从PHP生成渐变颜色 [英] Generate gradient color from PHP

查看:897
本文介绍了从PHP生成渐变颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何构建一个给出颜色代码的函数,
显示这个颜色的渐变。例如:

 函数generate_color(int colorindex)
{.......
。 ......
生成10种颜色的浅色。


}

请帮助我

解决方案

代码迈克尔引用是可怕的。但解决方案很简单。如果你只考虑一个灰度图像,可能会更清楚:

  function create_pallette($ start,$ end,$ entries = 10 )
{
$ inc =($ start - $ end)/($ entries-1);
$ out = array(0 => $ start);
for($ x = 1; $ x< $ entries; $ x ++){
$ out [$ x] = $ start + $ inc * $ x;
}
return $ out;
}

仅使用3D向量(RGB) p>

C。


I want to know how to build a function that give the code of an color and display a gradient of this color. For example:

function generate_color(int colorindex)
{  .......
   .......
   Generate 10  pale colors of this color.


}

Please help me

解决方案

The code Michael references is rather scary. But the solution is straightforward. It may be clearer if you consider simply a grey scale image:

 function create_pallette($start, $end, $entries=10)
 {
    $inc=($start - $end)/($entries-1);
    $out=array(0=>$start);
    for ($x=1; $x<$entries;$x++) {
      $out[$x]=$start+$inc * $x;
    }
    return $out;
 }

Only using a 3D vector (RGB) instead of a 1D vector.

C.

这篇关于从PHP生成渐变颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆