All Projects → bernaferrari → Hsluv Dart

bernaferrari / Hsluv Dart

Licence: mit
Dart port of HSLuv, a human-friendly alternative to HSL based on human experiments.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Hsluv Dart

vscode-color
Helper with GUI to generate color codes such as CSS color notations.
Stars: ✭ 88 (+79.59%)
Mutual labels:  color-picker, hsl, rgb
React Colorpickr
A themeable colorpicker with HSL and RGB support for React
Stars: ✭ 180 (+267.35%)
Mutual labels:  rgb, hsl, color-picker
andColorPicker
Color picker library for Android
Stars: ✭ 233 (+375.51%)
Mutual labels:  color-picker, hsl, rgb
Color Studio
It is too hard to build coherent and accessible themes with the right colors. This should help.
Stars: ✭ 289 (+489.8%)
Mutual labels:  rgb, hsl, color-picker
ColorPicker
Customizable Color Picker control for WPF
Stars: ✭ 57 (+16.33%)
Mutual labels:  color-picker, hsl, rgb
global-color-picker
start the script and click anywhere to get rgb value at the cursor location
Stars: ✭ 31 (-36.73%)
Mutual labels:  color-picker, rgb
ColorMinePortable
ColorMinePortable
Stars: ✭ 37 (-24.49%)
Mutual labels:  hsl, rgb
color
Standard representation of colors, encouraging sharing between packages.
Stars: ✭ 23 (-53.06%)
Mutual labels:  hsl, rgb
Colorpicker
A mininal but complete colorpicker desktop app
Stars: ✭ 766 (+1463.27%)
Mutual labels:  rgb, color-picker
przm
🎨 A simple, yet feature rich color picker and manipulator
Stars: ✭ 19 (-61.22%)
Mutual labels:  color-picker, rgb
colorsys.rs
Lib for modifying colors and converting to other spaces
Stars: ✭ 28 (-42.86%)
Mutual labels:  hsl, rgb
Farge
🎈Tell the name of hex color
Stars: ✭ 23 (-53.06%)
Mutual labels:  hsl, rgb
ColorTranslator
A JavaScript library, written in TypeScript, to convert among different color models
Stars: ✭ 34 (-30.61%)
Mutual labels:  hsl, rgb
color
A library of well-tested helper methods for working with colors.
Stars: ✭ 13 (-73.47%)
Mutual labels:  hsl, rgb
ColorHelper
No description or website provided.
Stars: ✭ 34 (-30.61%)
Mutual labels:  hsl, rgb
colors-convert
🦚 A simple colors library
Stars: ✭ 15 (-69.39%)
Mutual labels:  hsl, rgb
pigment
A powerful library that provides color-conversions, palette/scheme generation, color manipulation and many more features intended to provide a great UX.
Stars: ✭ 23 (-53.06%)
Mutual labels:  hsl, rgb
Culori
A comprehensive color library for JavaScript.
Stars: ✭ 271 (+453.06%)
Mutual labels:  rgb, hsl
tc-lib-color
PHP library to manipulate various color representations
Stars: ✭ 19 (-61.22%)
Mutual labels:  hsl, rgb
khroma
A collection of functions for manipulating CSS colors, inspired by SASS.
Stars: ✭ 28 (-42.86%)
Mutual labels:  hsl, rgb

Logo of HSLuv for Dart & Flutter

HSLuv for Dart & Flutter

Dart port of HSLuv (revision 4) with a Flutter sample. This was a direct conversion of the reference implementation. The sample is available as a web app.

HSLuv is a human-friendly alternative to HSL.

It is like HSL, but color only gets perceptually lighter or darker when the Lightness attribute changes. In HSL, if you go from a green hue to a red one, there will be big differences in the perceived lightness. In HSLuv, almost none.

If you want to see for yourself, check the sample app and open the Color Compare screen. Contrast "only" changes when Lightness changes. When Hue or Saturation attributes change, there might be minimal changes in contrast (in the 0.01 range), but nothing perceivable and certainly better than HSV/HSL.

This is specially useful when building acessible color systems. For more information, check: Designing Color Spaces / Wikipedia article

Usage

In the pubspec.yaml of your flutter project, add the following dependency:

pub package

dependencies:
  hsluv: ^VERSION

In your project you can use it in two different ways, either low level (directly accessing values as a list<double>) or high level (similar to HSLColor). HSLuvColor is easier to use, but has less flexibility than a raw list.

import 'package:hsluv/hsluv.dart';

void main() {

  // Low level usage.
  final List<double> hsluvLow = Hsluv.rgbToHsluv([0.2,0.5,0.7]);
  print(Hsluv.hsluvToHex(hsluvLow));

  // High level usage.
  final hsluvFromColor = HSLuvColor.fromColor(Colors(0xffef3e4a));
  print(hsluvFromColor.toString());

  final hsluvFromHSL = HSLuvColor.fromHSL(300, 70, 60);
  print(hsluvFromHSL.toString());
}

Sample app showing HSV (top) vs HSLuv (bottom). See how the perceived lightness changes as the hue slider moves.

Color values ranges

  • RGB values are ranging in [0...1]
  • HSLuv and HPLuv values have different ranging for their components
    • H : [0...360]
    • S and L : [0...100]
  • LUV has different ranging for their components
    • L* : [0...100]
    • u* and v* : [-100...100]
  • LCh has different ranging for their components
    • L* : [0...100]
    • C* : [0...?] Upper bound varies depending on L* and H*
    • H* : [0...360]
  • XYZ values are ranging in [0...1]

Important: Flutter's HSLColor has lightness and saturation ranging from 0 to 1.0. HSLuv uses 0 to 100. There is a class, called HSInterColor in the sample that tries to mitigate this.

API functions

Note

The passing/returning values, when not String are List<double> containing each component of the given color space/system in the name's order :

  • RGB : [red, blue, green]
  • XYZ : [X, Y, Z]
  • LCH : [L, C, H]
  • LUV : [L, u, v]
  • HSLuv/HPLuv : [H, S, L]

Function listing

  • xyzToRgb(List<double> tuple)
  • rgbToXyz(List<double> tuple)
  • xyzToLuv(List<double> tuple)
  • luvToXyz(List<double> tuple)
  • luvToLch(List<double> tuple)
  • lchToLuv(List<double> tuple)
  • hsluvToLch(List<double> tuple)
  • lchToHsluv(List<double> tuple)
  • hpluvToLch(List<double> tuple)
  • lchToHpluv(List<double> tuple)
  • lchToRgb(List<double> tuple)
  • rgbToLch(List<double> tuple)
  • hsluvToRgb(List<double> tuple)
  • rgbToHsluv(List<double> tuple)
  • hpluvToRgb(List<double> tuple)
  • rgbToHpluv(List<double> tuple)
  • hsluvToHex(List<double> tuple)
  • hpluvToHex(List<double> tuple)
  • hexToHsluv(String s)
  • hexToHpluv(String s)
  • rgbToHex(List<double> tuple)
  • hexToRgb(String hex)

Reporting Issues

Issues and Pull Requests are welcome. You can report here.

License

Copyright 2020 Bernardo Ferrari

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].