Graphi...::Value(3pm)
π Graphics::Toolkit::Color::Value β the vibe check for color values π
okay bestie, so this is Graphics::Toolkit::Color::Value, a lil' Perl module (that's the (3pm) situation) that handles the whole "is this color value even legal" thing. She checks, she converts, she measures. She does NOT want to be used directly by you though β she's basically the backstage crew for Graphics::Toolkit::Color. iykyk π
β¨ NAME β¨
Graphics::Toolkit::Color::Value β check, convert and measure color values. that's the whole job. three things. she's focused like that. π
πΈ SYNOPSIS πΈ
use Graphics::Toolkit::Color::Value; # import nothing
use Graphics::Toolkit::Color::Value ':all'; # import all routines
check_rgb( 256, 10, 12 ); # throws error 255 is the limit
my @hsl = hsl_from_rgb( 20, 50, 70 ); # convert from RGB to HSL space
no cap, that second one is giving "give me everything you've got" energy β :all really does import every single routine. and yes, check_rgb( 256, 10, 12 ) is a throw, because 255 is literally the limit and she will not be gaslit about it π
π¦ DESCRIPTION π¦
A whole little friend group of helper routines for handling RGB and HSL values: bound checks, conversion, and measurement. Most subs want three numerical values, sometimes it's two triplets. π«Ά
Heads up bestie: this module is supposed to be used by Graphics::Toolkit::Color, not directly by you. she's not being rude, she's just built different β as in, built for internal use. π
π ROUTINES π
π₯ check_rgb
Sends a Carp error message if the RGB value triplet isn't valid β or if it's straight up out of range. she will call you out, lovingly, with a Carp π
π₯ check_hsl
Same deal but for HSL: Carp error message if the HSL value triplet isn't valid, or out of value range. π
π₯ trim_rgb
Changes the RGB triplet to the nearest valid values. not shaming it, just nudging it back into range. slay. β¨
π₯ trim_hsl
Changes the HSL triplet to the nearest valid values. same energy, different color space. π
π₯ hsl_from_rgb
Converting an rgb value triplet into the corresponding hsl. periodt.
Here's the rules, bestie, write them down:
- Red, Green and Blue are integers in
0 .. 255. - Hue is an integer between
0 .. 359. - Saturation and lightness are
0 .. 100(percentage).
A hue of 360 and 0 (degree in a cylindrical coordinate system) is considered to be the same β and this module deals only with the latter. π§
π₯ rgb_from_hsl
Converting an hsl value triplet into the corresponding rgb (peep rgb_from_name and hsl_from_name for related stuff).
β οΈ Please note: going back and forth can lead to drifting results because of rounding. it's not a bug, it's just math being math π
my @rgb = rgb_from_hsl( 0, 90, 50 );
my @rgb = rgb_from_hsl( [0, 90, 50] ); # works too
# for real (none integer results), any none zero value works as second arg
my @rgb = rgb_from_hsl( [0, 90, 50], 'real');
π₯ hex_from_rgb
Converts a red green blue triplet into the format: '#RRGGBB'. iconic format, no notes π
π₯ rgb_from_hex
Converts '#RRGGBB' or '#RGB' hex values into a regular RGB triple of 0..255. short form and long form both eat. π
π₯ distance_rgb
Distance in (linear) rgb color space between two coordinates.
my $d = distance_rgb([1,1,1], [2,2,2]); # approx 1.7
π₯ distance_hsl
Distance in (cylindrical) hsl color space between two coordinates.
my $d = distance_rgb([1,1,1], [356, 3, 2]); # approx 6
π COPYRIGHT & LICENSE π
Copyright 2022 Herbert Breunung.
This program is free software; you can redistribute it and/or modify it under same terms as Perl itself. so go off, remix her, just keep the same terms fr fr π«Ά
π AUTHOR π
Herbert Breunung, <lichtkind@cpan.org>. the main character who wrote all this. give them their flowers πΈ
and that's the whole page, bestie β brought to you by perl v5.36.0, dated 2023-01-30, from the Graphi...::Value(3pm) era (yes the title is abbreviated, she's mysterious like that π). go forth and convert responsibly. mwah π
π¦ where this page comes from
- debian bookworm: libgraphics-toolkit-color-perl 1.08-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms