Skip to content

Instantly share code, notes, and snippets.

@jsvnm
Created March 4, 2013 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsvnm/5082688 to your computer and use it in GitHub Desktop.
Save jsvnm/5082688 to your computer and use it in GitHub Desktop.
replace #FAABAE colors in css with hsl(1,2,3) style, and invert lightness while doing that
require "color";
class Hex2InvertedHSL
def initialize; @convs={}; end;
def do(line)
line.gsub(/#[0-9a-fA-F]{6}/) { |hex|
@convs[hex] || (@convs[hex]=conv(hex))
}
end
def hex2hsl(hex)
_, *hex = hex.unpack("A1A2A2A2");
Color::RGB.new(*(hex.map { |val| val.to_i(16) })).to_hsl;
end
def conv(hex)
hsl=hex2hsl(hex)
hsl.l=1.0-hsl.l; # invert lightness
hsl.css_hsl;
end
end
h2hsl = Hex2InvertedHSL.new
while(gets)
puts h2hsl.do($_)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment