https://github.com/hsluv/hsluv-crystal
An implementation of the HSLuv colorspace (revision 4) in Crystal
https://github.com/hsluv/hsluv-crystal
Last synced: 8 months ago
JSON representation
An implementation of the HSLuv colorspace (revision 4) in Crystal
- Host: GitHub
- URL: https://github.com/hsluv/hsluv-crystal
- Owner: hsluv
- License: mit
- Created: 2020-08-20T20:46:52.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-01T19:19:57.000Z (about 5 years ago)
- Last Synced: 2025-07-11T11:19:53.645Z (11 months ago)
- Language: Crystal
- Homepage:
- Size: 1010 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hsluv-crystal
[](https://github.com/hsluv/hsluv-crystal/actions/workflows/crystal.yml)
An implementation of the [HSLuv](https://www.hsluv.org/) colorspace written in
crystal. Adapted from [hsluv-ruby](https://github.com/hsluv/hsluv-ruby).
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
hsluv:
github: hsluv/hsluv-crystal
```
2. Run `shards install`
## Usage
#### Including the library
```crystal
require "hsluv"
```
#### Parameter ranges
- `hue` is a Float64 between 0 and 360
- `saturation` is a Float64 between 0 and 100
- `lightness` is a Float64 between 0 and 100
- `hex` is the hexadecimal string representation of a color in "#rrggbb" format
- `red` is a Float64 between 0 and 1
- `green` is a Float64 between 0 and 1
- `blue` 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
1. Run `crystal spec` in the project directory
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Seth Hinz](https://github.com/your-github-user) - port author, maintainer