A Ruby implementation of HSLuv.
Add this line to your application's Gemfile:
gem'hsluv'And then execute:
$ bundle
Or install it yourself as:
$ gem install hsluv
hueis a float between 0 and 360saturationis a float between 0 and 100lightnessis a float between 0 and 100hexis the hexadecimal format of the colorredis a float between 0 and 1greenis a float between 0 and 1blueis a float between 0 and 1
Hsluv.hsluv_to_hex(12.177,100,53.23)=>#ff0000Hsluv.hsluv_to_rgb(12.177,100,53.23)=>[0.9998643703868711,6.849859221502719e-14,8.791283550555612e-06]Hsluv.hex_to_hsluv("#ff0000")=>[12.177050630061776,100.0000000000022,53.23711559542933]Hsluv.rgb_to_hsluv(0.99,6.84e-14,8.79e-16)=>[12.17705063006216,100.00000000000209,52.711595266911985]For HPLuv (the pastel variant), use:
hpluv_to_hexhpluv_to_rgbhex_to_hpluvrgb_to_hpluv
If you don't have Ruby installed already, I recommend using our devcontainer.json configuration to launch your editor in a pre-built Ruby container. Also consider using GitHub "Codespaces" feature if you don't use Docker.
Initial setup:
bundle installTest:
bundle exec rspec- Log in to rubygems.org using our shared hsluv profile
- Make a new API key if necessary, copy it to GitHub Actions
HSLUV_RUBYGEMS_API_KEYsecret - Update hsluv.gemspec with new version, e.g.
1.0.2.rc1, push to a branch - Run gem.yml workflow on that branch
- Sanity check:
gem install --user-install hsluv -v 1.0.2.rc1
1.0.2
- Add HSLuv revision 4 support (thanks @felix-d)