Color
A simple library for dealing with colors. Currently it features:
Conversion:
RGB Int <-> RGB Hex
HSL <-> RGB
RGB <-> CMYK
RGB -> HSV
Manipulation:
Mixing colors
Adjusting Hue, Saturation, or Lightness values of a color
Future plans include #to_web_safe, a palette (fe: Color.new(:black)), color wheel traversing ( Color.new(:red).compliment == Color.new(:green) ), and possibly color scheme suggestions (analagous, etc).
Usage
require ‘color’
> true
red = Color.new(‘ff0000’)
> #<Color:0x352fd0 @hue=0.0, @lightness=0.5, @rgb=[255, 0, 0], @saturation=1.0>
yellow = Color.new(‘ffff00’)
> #<Color:0x34bb18 @hue=0.166666666666667, @lightness=0.5, @rgb=[255, 255, 0], @saturation=1.0>
orange = red.mix_with yellow, 0.5
> #<Color:0x33dea0 @hue=0.0830065359477123, @lightness=0.5, @rgb=[255, 127, 0], @saturation=1.0>
orange.to_hex
> “#ff7f00”
orange.lightness += 0.2
> 0.7
orange.to_hex
> “#ffb266”
Warning
This is alpha-quality software. It works according to general poking and prodding, but at this point all of half a morning has been spent on it. The API is subject to change.