From: Austin Ziegler Date: 2007-12-01T09:18:55+09:00 Subject: Re: Convert HEX to RGB On 11/30/07, Jeremy Hinegardner wrote: > On Fri, Nov 30, 2007 at 07:59:15PM +0900, Eust?quio 'TaQ' Rangel wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > > Ummm... This is a really clever solution, except if you have a hex value > > > that you need to convert into an rgb array, it is probably a string, not > > > an integer literal. Is there an easy way to convert a hex string > > > directly into an integer literal? > > > > Gimme a good and old blue RGB: > > > > >> "101aff".scan(/../).map {|color| color.to_i(16)} > > => [16, 26, 255] > > Or use color (http://rubyforge.org/projects/color/) > > require 'rubygems' > require 'color' > > c = Color::RGB.from_html("101aff") > c.css_rgb # => rgb(6.27%, 10.20%, 100.00%) > [c.red, c.green, c.blue] # => [16.0, 26.0, 255.0] Why thank you, Jeremy. ;) What's beautiful about the Color rubygem is that it's a lot more than just RGB, too. Much much more. -austin, thinking he should try to conscript Jeremy into helping out with Color again... -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca