## Friday, August 24, 2012

### Converting from a hex-string color to its rgbvalue

There are several ways to specify color when one plots using gnuplot.Among them hex-string (like "#0000ff") and rgbvalue (like "256") specification is very important. In this post we will talk about converting from a hex-string color to its rgbvalue (the inversion will be talked in another post).

```reset
#pick the red color hex string out
red(colorstring)= colorstring[2:3]
#pick the green color hex string out
green(colorstring)=colorstring[4:5]
#pick the blue color hex string out
blue(colorstring)=colorstring[6:7]
#convert a hex string to its dec format
hex2dec(hex)=gprintf("%0.f",int('0X'.hex))
#calculate the rgb value from the r,g,b weight
rgb(r,g,b) = 65536*int(r)+256*int(g)+int(b)
#convert the hex color string to its rgb value.
hex2rgbvalue(color)=rgb(\
hex2dec(red(color)),\
hex2dec(green(color)),\
hex2dec(blue(color))\
)
set term png
set output "hex_string2rgbvalue.png"
plot 'color.dat' u 1:2:(hex2rgbvalue(stringcolumn(3)))\
w lp pt 7 ps 3 lc rgb variable notitle
set output
```

File 'color.dat' has content like the following:
```0 1 #ff0000
1 2 #00ff00
2 3 #0000ff
3 4 #ff00ff
4 5 #ffff00
5 6 #00ffff
0 6 #00ffff
1 5 #ffff00
2 4 #ff00ff
3 3 #0000ff
4 2 #00ff00
5 1 #ff0000
```

The output file 'hex_string2rgbvalue.png' looks like this:
 Fig.1 Converting from a hex-string color to its rgb-value

1. Hadoop concepts, Applying modelling through R programming using Machine learning algorithms and illustrate impeccable Data Visualization by leveraging on 'R' capabilities.With companies across industries striving to bring their research and analysis (R&A) departments up to speed, the demand for qualified data scientists is rising.
data science training in bangalore

2. Nice article. It's very helpful to me. Thank you for share with us. Can you please check my rgba color picker online tool.

3. Nice article. It's very helpful to me. Thank you for share with us. Can you please check my hexadecimal color codes online tool.

5. There is a magnificent portrayal of each vital concern and that too in a compact way. Creator did his employment superbly. He prevails to convey his contemplations with best of his insight and I am truly exceptionally inspired with his endeavors. png to svg

6. that is the number one time I came to this blog and i discovered a few applicable stuff proper right here. essentially I keen to realize new parameters of writing every-time and someday it turn out to be actually very tough to find such type of platform. png to svg

7. Super Vectorizer automatically converts PNG files to SVG graphics on Mac and make the svg results easier to edit and adjust. png to svg

8. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me. hex to decimal conversion

9. Compre documentos en línea, documentos originales y registrados.
Acerca de Permisodeespana, algunos dicen que somos los solucionadores de problemas, mientras que otros se refieren a nosotros como vendedores de soluciones. Contamos con cientos de clientes satisfechos a nivel mundial. Hacemos documentos falsos autorizados y aprobados como Permiso de Residencia Español, DNI, Pasaporte Español y Licencia de Conducir Española. Somos los fabricantes y proveedores de primer nivel de estos documentos, reconocidos a nivel mundial.

Comprar permiso de residencia,
permiso de residenciareal y falso en línea,
Compre licencia de conducir en línea,
Compre una licencia de conducir española falsa en línea,
Comprar tarjeta de identificación,
Licencia de conducir real y falsa,
Compre pasaporte real en línea,