Reputation: 17189
I know there is a gem called Color. I installed it.
But for the life of me, I can't figure out how to use the thing.
I just want to convert a color name into its RGB values, if possible without copying the whole color table into my code.
I want to be able to convert something like red
or Navy
into three numeric values.
Upvotes: 7
Views: 2915
Reputation: 905
Old question, but I just came across this gem in a current project and had to do the same. I needed RBG values like OP asked for and so I used the css_rbg
instance method similar to how tokland produced the hex value with the html
instance method.
require 'color/css'
red_code = Color::CSS["red"].css_rgb
#=> "rgb(100.00%, 0.00%, 0.00%)"
Upvotes: 0
Reputation: 67850
require 'color/css'
red_code = Color::CSS["red"].html
#=> "#ff0000"
Upvotes: 11
Reputation: 3995
Html colours are expressed as an Hexadecimal colour, and it turns out that a RGB colour is not more than a Hexadecimal expression of the colour so:
#ff0000 = r:255 g:0 b:0
Upvotes: -1