Skip to content

Instantly share code, notes, and snippets.

@lunelson
Created April 23, 2013 18:21
Show Gist options
  • Save lunelson/5446053 to your computer and use it in GitHub Desktop.
Save lunelson/5446053 to your computer and use it in GitHub Desktop.
SassScript to expose "husler" HUSL color functions
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