Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created January 5, 2015 14:04
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 mahemoff/7920b7b1b8832bfeff17 to your computer and use it in GitHub Desktop.
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
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