Color Functions

© 2012, Martin Rinehart

color2rgb()

[red, green, blue] = color2rgb( '#rrggbb' );

Convert hex color string to array of decimal values.

Example: '#00ffff' converts to [ 0, 255, 255 ].

hex_color_string()

hex_string = hex_color_string( unknown_color_string );

Convert 'rgb( rrr, ggg, bbb)' to '#rrggbb'. Some browsers will take xxx.style.backgroundColor = '#f0f0ff'; and then assign 'rgb( 240, 240, 255 )' to xxx.style.backgroundColor. This will read either and emit the #rrggbb form.

rgb2color()

hex_string = rgb2color( red, green, blue );

Converts three decimal numbers (for red, green and blue) into hex color string.

Example: rgb2color( 0, 255, 255 ); returns '#00ffff'.


Feedback: MartinRinehart at gmail dot com

# # #