Rand Stats

Color::Palette

zef:jkramer

Actions Status

NAME

Color::Palette

SYNOPSIS

use Color::Palette;
use Color;

my $palette = Color::Palette::from-gpl('pantone.gpl'.IO.slurp);

$palette.add-color(Color.new(0, 0, 0), 'Black');
$palette.add-color(Color.new(255, 0, 0));
$palette.=sort(:by<hsv>);
$palette.=unique(:by<color>);
$palette.name = 'Lots of Colors';
$palette.columns = 5;

say $palette.to-gpl;

DESCRIPTION

Module for working with color palettes. Currently supports:

Todo:

ATTRIBUTES

@colors

Array of NamedColor objects. NamedColor is a simple class that holds a Color and an optional color name.

$name

Optional name of the color palette.

$columns

Specifies the number of columns to display the palette on in GIMP (only relevant when generating GPL files for use in GIMP).

METHODS / SUBS

::from-gpl(Str:D $input)

my $palette = Color::Palette::from-gpl('palette.gpl'.IO.slurp);

Creates and returns a Color::Palette object with the contents parsed from the given input string in GPL format.

.to-gpl

Returns a string with the palette in GPL format.

.add-color(Color $color, Str $name?)

$palette.add-color(Color.new(0, 0, 0), 'Black');
$palette.add-color(Color.new(255, 0, 0));

Adds a color with an optional color name to the palette.

.sort(Str :$by)

$palette.=sort(:by<hsv>, :reverse);

Returns a copy of the palette with the colors sorted using the algorithm/criteria. Currently supported:

:reverse reverses the order of the colors after sorting.

.unique(:by<color>)

$palette.=unique(:by<color>);

Returns a copy of the palette with duplicate colors removed. color detects duplicates by comparing the RGB values of the color, name checks for duplicate names.

SEE ALSO

AUTHOR

Jonas Kramer jkramer@mark17.net

COPYRIGHT AND LICENSE

Copyright 2024 Jonas Kramer

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.