Created
March 4, 2013 14:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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