Module: Workbench::ColorHelper
- Defined in:
- app/helpers/workbench/color_helper.rb
Class Method Summary collapse
- .hexstr_to_signed32int(hexstr) ⇒ Object
-
.ranged_color(v = 0.0, c = 'blue') ⇒ Object
wow division is odd in Ruby! (.to_f).
- .signed32int_to_hexstr(int) ⇒ Object
Instance Method Summary collapse
Class Method Details
.hexstr_to_signed32int(hexstr) ⇒ Object
17 18 19 20 21 |
# File 'app/helpers/workbench/color_helper.rb', line 17 def self.hexstr_to_signed32int(hexstr) # return nil if hexstr =~ /^[0-9A-Fa-f]{1,8}$/ num = hexstr.to_i(16) return (num > 31 ? num - 2 ** 32 : num) end |
.ranged_color(v = 0.0, c = 'blue') ⇒ Object
wow division is odd in Ruby! (.to_f)
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/workbench/color_helper.rb', line 32 def self.ranged_color(v = 0.0, c = 'blue') n = 240 - (v * 240).to_i case c when 'blue' "#{n}, #{n}, 240" when 'red' "240, #{n}, #{n}" when 'green' "#{n}, 240, #{n}" end end |
.signed32int_to_hexstr(int) ⇒ Object
24 25 26 27 28 |
# File 'app/helpers/workbench/color_helper.rb', line 24 def self.signed32int_to_hexstr (int) return nil if int > 2147483647 || int < -2147483648 unsigned = (int < 0 ? 2 ** 32 + int : int) return ("%x" % unsigned) end |
Instance Method Details
#contrast_hex(hex_color) ⇒ Object
10 11 12 13 |
# File 'app/helpers/workbench/color_helper.rb', line 10 def contrast_hex(hex_color) c = RGB::Color.from_rgb_hex(hex_color) RGB::Color.from_rgb( *c.to_rgb.collect{|a| 255 - a} ).to_rgb_hex end |
#inverse_hex(hex_color) ⇒ Object
5 6 7 8 |
# File 'app/helpers/workbench/color_helper.rb', line 5 def inverse_hex(hex_color) c = RGB::Color.from_rgb_hex(hex_color) RGB::Color.from_rgb( *c.to_rgb.collect{|a| 255 - a} ).to_rgb_hex end |