Created
January 5, 2015 14:04
-
-
Save mahemoff/7920b7b1b8832bfeff17 to your computer and use it in GitHub Desktop.
Color manipulation - Proof-of-concept Ruby library for color manipulation by building on Sass
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
class Rainbow | |
def sass(command) | |
@@parser ||= Sass::Script::Parser | |
@@env = Sass::Environment.new | |
@@parser.parse(command, 0, 0).perform @@env | |
end | |
def saturation(color, amount) # amount is between -1 and 1 | |
sass "change-color(#{color}, $saturation: #{100*amount})" | |
end | |
def lightness(color, amount) # amount is between -1 and 1 | |
sass "change-color(#{color}, $lightness: #{100*amount})" | |
end | |
def color(color, options) | |
options = options.mash | |
opts = [] | |
opts << "$lightness: #{100 * options.l}" if options.l | |
opts << "$saturation: #{100 * options.s}" if options.s | |
sass "change-color(#{color}, #{opts.join(',')})" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment