ColorCode
simple handle the color code
Installation
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
Usage
RGB class
rgb = ColorCode::RGB.new(r: 255, g: 0, b: 0) rgb.to_s # => '#ff0000' rbg.to_hash # => { r: 255, g: 0, b: 0 }
HSV class
hsv = ColorCode::HSV.new(h: 0, s: 100, v: 100) hsv.to_s # => '#ff0000' hsv.to_hash # => { h: 0, s: 100, v: 100 }
HSL class
hsl = ColorCode::HSL.new(h: 0, s: 100, l: 50) hsl.to_s # => '#ff0000' hsl.to_hash # => { h: 0, s: 100, l: 50 }
convert RGB to HSV
rgb = ColorCode::RGB.new(r: 255, g: 0, b: 0) rgb.to_s # => '#ff0000' hsv = rgb.to_hsv hsv.to_s # => '#ff0000'
convert HSL to RGB
hsv = ColorCode::HSV.new(h: 0, s: 100, v: 100) hsv.to_s # => '#ff0000' rgb = hsv.to_rgb rgb.to_s # => '#ff0000'
convert RGB to HSL
rgb = ColorCode::RGB.new(r: 255, g: 0, b: 0) rgb.to_s # => '#ff0000' hsl = rgb.to_hsl hsl.to_s # => '#ff0000'
convert HSL to RGB
hsl = ColorCode::HSL.new(h: 0, s: 100, l: 50) hsl.to_s # => '#ff0000' rgb = hsl.to_rgb rgb.to_s # => '#ff0000'
Contributing
- Fork it ( https://github.com/shiro16/color_code/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request