17 static void r2hex(
float r,
char *h){
19 static char hex[] =
"0123456789abcdef";
20 int i = (
int)(255*r+0.5);
27 void rgb2hex(
float r,
float g,
float b,
char *cstring,
char *opacity){
29 r2hex(r, &(cstring[1]));
30 r2hex(g, &(cstring[3]));
31 r2hex(b, &(cstring[5]));
33 if (opacity && strlen(opacity) >= 2){
34 cstring[7] = opacity[0];
35 cstring[8] = opacity[1];
45 if((6.0*H) < 1.0)
return (v1 + (v2 - v1) * 6.0 * H);
46 if((2.0*H) < 1.0)
return v2;
47 if((3.0*H) < 2.0)
return (v1 + (v2 - v1) * ((2.0/3.0) - H) * 6.0);
51 char *hex[16]={
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f"};
54 real v1, v2, lightness = .5, saturation = 1;
58 v2 = lightness * (1.0 + saturation);
60 v2 = (lightness + saturation) - (saturation * lightness);
62 v1 = 2.0 * lightness - v2;
64 red = (
int)(255.0 *
Hue2RGB(v1, v2, hue + (1.0/3.0)) + 0.5);
65 green = (
int)(255.0 *
Hue2RGB(v1, v2, hue) + 0.5);
66 blue = (
int)(255.0 *
Hue2RGB(v1, v2, hue - (1.0/3.0)) + 0.5);
68 sprintf(color+1,
"%s",hex[red/16]);
69 sprintf(color+2,
"%s",hex[red%16]);
70 sprintf(color+3,
"%s",hex[green/16]);
71 sprintf(color+4,
"%s",hex[green%16]);
72 sprintf(color+5,
"%s",hex[blue/16]);
73 sprintf(color+6,
"%s",hex[blue%16]);
80 real v1, v2, lightness = .5, saturation = 1;
84 v2 = lightness * (1.0 + saturation);
86 v2 = (lightness + saturation) - (saturation * lightness);
88 v1 = 2.0 * lightness - v2;
90 red = (
int)(255.0 *
Hue2RGB(v1, v2, hue + (1.0/3.0)) + 0.5);
91 green = (
int)(255.0 *
Hue2RGB(v1, v2, hue) + 0.5);
92 blue = (
int)(255.0 *
Hue2RGB(v1, v2, hue - (1.0/3.0)) + 0.5);
96 color[1] = green/255.;
void rgb2hex(float r, float g, float b, char *cstring, char *opacity)
char * hue2rgb(real hue, char *color)
real Hue2RGB(real v1, real v2, real H)
void hue2rgb_real(real hue, real *color)