Created
April 23, 2013 18:21
-
-
Save lunelson/5446053 to your computer and use it in GitHub Desktop.
SassScript to expose "husler" HUSL color functions
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 'sass' | |
require 'husler' | |
module Sass::Script::Functions | |
module Husl | |
def husl_to_rgb(h, s, l) # assume h (0-360) s, l (0-100) | |
h = h.to_f | |
Husler.husl_to_rgb(h,s,l) | |
end | |
def rgb_to_husl(r, g, b) # assume r,g,b (0-255) | |
r /= 255 | |
g /= 255 | |
b /= 255 | |
Husler.rgb_to_husl(r,g,b) | |
end | |
def husl_to_hex(h, s, l) # assume h (0-360) s, l (0-100) | |
Husler.husl_to_hex(h,s,l) | |
end | |
def hex_to_husl(hex) # assume 6-character hex string | |
Husler.hex_to_husl(hex) | |
end | |
def husl(h,s,l) | |
c = Husler.husl_to_rgb(h,s,l) | |
rgb(c[0]*255,c[1]*255,c[2]*255) | |
end | |
def husla(h,s,l,a) | |
c = Husler.husl_to_rgb(h,s,l) | |
rgba(c[0]*255,c[1]*255,c[2]*255,a) | |
end | |
end | |
include Husl | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment