Colour mathematics (RGB/HSL/blend) library for Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A simple Ruby library to perform operations on RGB and HSL colours.


Instantiate an RGB (red, green, blue) colour:

orange =, 0.5, 0)

Or from a hex value via a helper method:

white  = ColorMath::hex_color("#fff")
blue   = ColorMath::hex_color("#0000ff")

Instantiate an HSL (hue, saturation, luminance) colour:

pink   =, 1, 0.88)

Retrieve the RGB components of a colour:    # => 1.0  # => 0.76   # => 0.8

Or the HSL components:

orange.hue         # => 30.0
orange.saturation  # =>  1.0
orange.luminance   # =>  0.5

Combine two colours via an alpha blend, e.g. 30% orange on white:

combined = ColorMath::Blend.alpha(white, orange, 0.3)

Convert a colour to hexadecimal representation:

combined.hex  # => "#ffd8b2"

That’s it. It only does the basics that I need for the job in hand, but it’s probably a good basis for extension.