A simple Ruby library built to handle easy conversion and manipulation of colors.
Branch: master
Clone or download
Latest commit 806f191 Mar 28, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Added Color#mix(other_color) May 10, 2015
spec
.gitignore Remove Gemfile.lock from .gitignore Apr 6, 2015
.rspec Update specs Mar 28, 2015
.travis.yml Add .travis.yml Mar 28, 2015
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT.md Mar 28, 2015
Gemfile Add Gemfile Mar 28, 2015
Gemfile.lock Remove Gemfile.lock from .gitignore Apr 6, 2015
LICENSE Update LICENSE Mar 28, 2017
NOTICE Add LICENSE Mar 28, 2015
README.md Added Color#mix(other_color) May 10, 2015
Rakefile
rgb.gemspec Update rgb.gemspec Mar 28, 2015

README.md

rgb — Easy colors manipulation

Gem Version Build Status

A simple Ruby library built to handle easy conversion and manipulation of colors. Inspired by compass-colors https://github.com/chriseppstein/compass-colors and jColour.js https://github.com/lingo/jcolour.

Examples

require 'rgb'

# Supported input data color formas:
color = RGB::Color.from_rgb_hex("#333333")
color = RGB::Color.from_rgb_hex(0xFF0000)
color = RGB::Color.from_rgb(115, 38, 38)
color = RGB::Color.from_fractions(0, 1.0, 0.5) # HSL

# Supported color manipulations:
color.darken(20)
color.darken_percent(10)
color.darken!(20)
color.darken_percent!(10)
color.lighten(20)
color.lighten_percent(20)
color.lighten!(20)
color.lighten_percent!(20)
color.saturate(20)
color.saturate_percent(20)
color.saturate!(20)
color.saturate_percent!(20)
color.desaturate(20)
color.desaturate_percent(20)
color.desaturate!(20)
color.desaturate_percent!(20)

color.invert!

# Mixing colors:
color.mix(other_color, 20) # Mix 20% of other color into current one
color.mix(other_color) # 50% by default
color.mix!(other_color, 20)
color.mix!(other_color)

# Also you can adjust color HSL (hue, saturation, and lightness values) manually:
color.hue = 0.1
color.saturation = 0.2
color.lightness = 0.3

# Supported output formats:
color.to_rgb_hex
=> "#732626"
color.to_hsl
=> [0, 1.0, 0.5]
color.to_rgb
=> [115, 38, 38]

Support

Feel free to create issues

License

Please see LICENSE for licensing details.