Graphi...::Value(3pm)

πŸ“¦ version 1.08, in debian bookworm

πŸ’– 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 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