Class: Rcade::Color
- Inherits:
-
Gosu::Color
- Object
- Gosu::Color
- Rcade::Color
- Defined in:
- lib/rcade_colors.rb
Class Method Summary collapse
-
.from_hex(string) ⇒ Object
hex argument should be a string and can be the full 6 digit hex or 3 digit shorthand and may include a # prefix.
- .named(color_name) ⇒ Object
Class Method Details
.from_hex(string) ⇒ Object
hex argument should be a string and can be the full 6 digit hex or 3 digit shorthand and may include a # prefix. Examples:
"fed"
"#fed"
"cabbed"
"#cabbed"
22 23 24 25 26 27 28 29 |
# File 'lib/rcade_colors.rb', line 22 def self.from_hex(string) h = string.scan(/\h/) if h.size == 3 h.map! {|v| (v * 2) } # expand to 6 character format end hex_string = "0xff" + h.join # fully opaque self.argb(hex_string.to_i(16)) end |
.named(color_name) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/rcade_colors.rb', line 31 def self.named(color_name) require 'color/css' color = ::Color::CSS[color_name] raise 'Invalid color name' unless color self.from_hex(color.html) end |