PHP中Hexcolor的百分比

Yos*_*ahu 2 php hex colors hsv

我想把一个百分比变成十六进制的颜色.有点HSV颜色度如何工作......
我正在使用PHP.

IE: 
  0% : RED       (#FF0000)
  8% : ORANGE    (#FF7F00)
 17% : YELLOW    (#FFFF00)
 25% : LIMEGREEN (#7FFF00)
 ... : ...
 83% : MAGENTA   (#FF00FF)
 92% : ROSE      (#FF007F)
100% : RED       (#FF0000)
Run Code Online (Sandbox Code Playgroud)

Ben*_*rne 6

这个小片段看起来像你想要实现的那样

http://bytes.com/topic/php/insights/890539-how-produce-first-pair-rgb-hex-color-value-percent-value

function percent2Color($value,$brightness = 255, $max = 100,$min = 0, $thirdColorHex = '00')
{       
    // Calculate first and second color (Inverse relationship)
    $first = (1-($value/$max))*$brightness;
    $second = ($value/$max)*$brightness;

    // Find the influence of the middle color (yellow if 1st and 2nd are red and green)
    $diff = abs($first-$second);    
    $influence = ($brightness-$diff)/2;     
    $first = intval($first + $influence);
    $second = intval($second + $influence);

    // Convert to HEX, format and return
    $firstHex = str_pad(dechex($first),2,0,STR_PAD_LEFT);     
    $secondHex = str_pad(dechex($second),2,0,STR_PAD_LEFT); 

    return $firstHex . $secondHex . $thirdColorHex ; 

    // alternatives:
    // return $thirdColorHex . $firstHex . $secondHex; 
    // return $firstHex . $thirdColorHex . $secondHex;

}
Run Code Online (Sandbox Code Playgroud)