Giter Site home page Giter Site logo

hsluv-ruby's Introduction

Ruby Gem Version

A Ruby implementation of HSLuv.

Installation

Add this line to your application's Gemfile:

gem 'hsluv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hsluv

Usage

  • hue is a float between 0 and 360
  • saturation is a float between 0 and 100
  • lightness is a float between 0 and 100
  • hex is the hexadecimal format of the color
  • red is a float between 0 and 1
  • green is a float between 0 and 1
  • blue is a float between 0 and 1

Hsluv::hsluv_to_hex(hue, saturation, lightness) -> color as a hex string

Hsluv.hsluv_to_hex(12.177, 100, 53.23)
=> #ff0000

Hsluv::hsluv_to_rgb(hue, saturation, lightness) -> color as rgb

Hsluv.hsluv_to_rgb(12.177, 100, 53.23)
=> [0.9998643703868711, 6.849859221502719e-14, 8.791283550555612e-06]

Hsluv::hex_to_hsluv(hex) -> list of floats as defined above

Hsluv.hex_to_hsluv("#ff0000")
=> [12.177050630061776, 100.0000000000022, 53.23711559542933]

Hsluv::rgb_to_hsluv(rgb) -> list of floats as defined above

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_hex
  • hpluv_to_rgb
  • hex_to_hpluv
  • rgb_to_hpluv

Local workflow

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 install

Test:

bundle exec rspec

Releasing a new version

  1. Log in to rubygems.org using our shared hsluv profile
  2. Make a new API key if necessary, copy it to GitHub Actions HSLUV_RUBYGEMS_API_KEY secret
  3. Update hsluv.gemspec with new version, e.g. 1.0.2.rc1, push to a branch
  4. Run gem.yml workflow on that branch
  5. Sanity check: gem install --user-install hsluv -v 1.0.2.rc1

Version history

1.0.2

  • Add HSLuv revision 4 support (thanks @felix-d)

hsluv-ruby's People

Contributors

boronine avatar felix-d avatar frederik-baetens avatar jish avatar radubogdan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hsluv-ruby's Issues

Support for Hex shorthand colors

Currently, Hsluv.hex_to_hsluv works with #ffffff, however, it doesn't work with #fff. I was wondering if there's a possibility to support the shorthand. If you think it's a good thing to have, I can try creating a PR.

> Hsluv.hex_to_hsluv('#fff')

ArgumentError: wrong number of arguments (given 2, expected 3)
from /nix/store/kn5y2xfa9gps4qdwklavf6hhrfml7dr3-ruby2.7.1-hsluv-1.0.1/lib/ruby/gems/2.7.0/gems/hsluv-1.0.1/lib/hsluv.rb:46:in `rgb_to_hsluv'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.