hsluv-crystal
hsluv-crystal
An implementation of the HSLuv colorspace written in crystal. Adapted from hsluv-ruby.
Installation
-
Add the dependency to your
shard.yml
:dependencies: hsluv: github: hsluv/hsluv-crystal
-
Run
shards install
Usage
Including the library
require "hsluv"
Parameter ranges
hue
is a Float64 between 0 and 360saturation
is a Float64 between 0 and 100lightness
is a Float64 between 0 and 100hex
is the hexadecimal string representation of a color in "#rrggbb" formatred
is a Float64 between 0 and 1green
is a Float64 between 0 and 1blue
is a Float64 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)
=> StaticArray[0.9998643703868711, 6.849859221502719e-14, 8.791283550555612e-06]
HSLuv::hex_to_hsluv(hex) -> list of floats as defined above
HSLuv.hex_to_hsluv("#ff0000")
=> StaticArray[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)
=> StaticArray[12.17705063006216, 100.00000000000209, 52.711595266911985]
For HPLuv (the pastel variant), use:
hpluv_to_hex
hpluv_to_rgb
hex_to_hpluv
rgb_to_hpluv
Testing
- Run
crystal spec
in the project directory
Contributing
- Fork it (https://github.com/shinzlet/hsluv-crystal/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
Contributors
- Seth Hinz - port author, maintainer
Repository
hsluv-crystal
Owner
Statistic
- 3
- 1
- 0
- 1
- 0
- over 3 years ago
- August 20, 2020
License
MIT License
Links
Synced at
Fri, 22 Nov 2024 16:04:27 GMT
Languages