color_models 0.2.3+2 copy "color_models: ^0.2.3+2" to clipboard
color_models: ^0.2.3+2 copied to clipboard

outdated

A set of classes representing the CMYK, HSI, HSL, HSP, HSV, LAB, RGB, and XYZ color spaces with methods to convert colors between each space.

color_models #

pub package style: effective dart

A package for defining color constants and converting them between color spaces.

For use with Flutter, see: https://pub-web.flutter-io.cn/packages/flutter_color_models

Usage #

import 'package:color_models/color_models.dart';

Color Spaces #

color_models exposes models for the CMYK, HSI, HSL, HSP, HSV, LAB, RGB, and XYZ color spaces; represented as [CmykColor], [HsiColor], [HslColor], [HspColor], [HsvColor], [LabColor], [RgbColor], and [XyzColor] respectively.

Each model is constant and extends [ColorModel].

Converting Colors Between Spaces #

Each color model has methods to convert itself to every other color model.

CmykColor toCmykColor();

HsiColor toHsiColor();

HslColor toHslColor();

HspColor toHspColor();

HsvColor toHsvColor();

LabColor toLabColor();

RgbColor toRgbColor();

XyzColor toXyzColor();

Altenatively, each color model has a static method from that returns a color from any color space in the color space being called.

static T from(ColorModel color);
// Create a HSV color
var originalColor = HsvColor(0.3, 0.8, 0.7);

// Convert it to RGB => RgbColor(64, 179, 36)
var rgbColor = RgbColor.from(originalColor);

// Then to CMYK => CmykColor(64.25, 0, 79.89, 29.8)
var cmykColor = CmykColor.from(rgbColor);

// Back to HSV => HsvColor(0.3, 0.8, 0.7)
var hsvColor = HsvColor.from(cmykColor);

Note: All color conversions use the RGB color space as an intermediary. To minimize the loss of precision when converting between other color spaces, [RgbColor] privately stores the RGB values as [num]s rather than [int]s. The [num] values can be returned as a list with [RgbColor]'s toPreciseList() method.

11
likes
0
pub points
81%
popularity

Publisher

verified publisherjamesalex.dev

A set of classes representing the CMYK, HSI, HSL, HSP, HSV, LAB, RGB, and XYZ color spaces with methods to convert colors between each space.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta

More

Packages that depend on color_models