Function generate_rgb

Function Documentation

function generate_rgb(str)

Compute Rgb triple for given CSS color name. The function returns the RGB (Red-Green-Blue) triple corresponding to the color name by the CSS3 proposed standard [1], which contains 139 different colors (an RGB triple is a 1x3 vector of numbers between 0 and 1). The input color name is case insensitive, and for gray colors both spellings (gray and grey) are allowed.

Usage:

  • c = Indigo.Utils.generate_rgb(‘DarkRed’): returns c = [0.5430 0 0].

  • c = Indigo.Utils.generate_rgb(‘Green’): returns c = [0 0.5 0].

  • plot(x, y, ‘color’, generate_rgb(‘Orange’)): plots an orange line through x and y.

  • Indigo.Utils.show_colors(): shows all the available colors.

Background: The color names of [1] have already been ratified in [2], and according to [3] they are accepted by almost all web browsers and are used in Microsoft’s .net framework. All but four colors agree with the X11 colornames, as detailed in [4]. Of these the most important clash is green, defined as [0 0.5 0] by CSS and [0 1 0] by X11. The definition of green in Matlab matches the X11 definition and gives a very light green, called lime by CSS (many users of Matlab have discovered this when trying to color graphs with ‘g-‘). Note that cyan and aqua are synonyms as well as magenta and fuchsia.

About: This program is public domain and may be distributed freely. Author: Kristjan Jonasson, Dept. of Computer Science, University of Iceland (). June 2009.

References: [1] “CSS Color module level 3”, W3C (World Wide Web Consortium) working draft 21 July 2008, http://www.w3.org/TR/css3-color [2] “Scalable Vector Graphics (SVG) 1.1 specification”, W3C recommendation 14 January 2003, edited in place 30 April 2009, http://www.w3.org/TR/SVG [3] “Web colors”, http://en.wikipedia.org/wiki/Web_colors [4] “X11 color names” http://en.wikipedia.org/wiki/X11_color_names

Parameters

str – Color string name.

Returns

Red-Green-Blue triple.