Conver...::RGB8(3pm)

πŸ’– Convert::Color::RGB8(3pm) β€” the manual page, but make it cute πŸ’–

okay bestie, buckle up, we're gonna talk about Convert::Color::RGB8, a Perl module that represents a color value as red/green/blue in 8-bit integers. no cap, it's giving tiny-numbers-big-energy. 🌈


✨ NAME ✨

Convert::Color::RGB8 β€” a color value represented as red/green/blue in 8-bit integers. literally what it says on the tin, she's an icon, she's a legend, and she's the moment. πŸ’…

✨ SYNOPSIS ✨

Directly, if you wanna go straight to the source:

use Convert::Color::RGB8;

my $red = Convert::Color::RGB8->new( 255, 0, 0 );

# Can also parse strings
my $pink = Convert::Color::RGB8->new( '255,192,192' );

# or
$pink = Convert::Color::RGB8->new( 'ffc0c0' );

Or via Convert::Color, if you like a middleman:

use Convert::Color;

my $cyan = Convert::Color->new( 'rgb8:0,255,255' );

both paths are valid and both are slay. 🫢

✨ DESCRIPTION ✨

Objects in this class represent a color in RGB space, as a set of three integer values in the range 0 to 255 β€” i.e. as 8 bits. that's it, that's the whole vibe. each channel is one byte, so the range is 0 to 255, inclusive, no negotiations. πŸŽ€

If you're more of a floating-point girly, go see Convert::Color::RGB. If you like your integers a lil chunkier, Convert::Color::RGB16 is right there. this one? 8-bit. periodt. πŸ’œ

✨ CONSTRUCTOR ✨

🌸 new

$color = Convert::Color::RGB8->new( $red, $green, $blue );

Returns a new object to represent the set of values given. These values should be integers between 0 and 255. Values outside of this range will be clamped β€” so bestie, if you pass something wild, she's not gonna error out, she's just gonna pin it to the edge. no drama, no shouting. πŸ™ˆ

$color = Convert::Color::RGB8->new( $string );

Parses $string for values, and constructs a new object similar to the above three-argument form. The string should be in the form:

red,green,blue

containing the three integer values in decimal notation. It can also be given in the form of a hex encoded string, such as would be returned by the rgb8_hex method:

rrggbb

so you've got options, and honestly? options are self-care. πŸ’–

✨ METHODS ✨

🌸 red

$r = $color->red;

🌸 green

$g = $color->green;

🌸 blue

$b = $color->blue;

Accessors for the three components of the color. one accessor per channel, as she deserves. πŸŽ€

🌸 rgb8

( $red, $green, $blue ) = $color->rgb8;

Returns the individual red, green and blue color components of the color value in RGB8 space. all three at once, like a little squad rolling up together. πŸ‘‘

🌸 hex

$str = $color->hex;

Returns a string representation of the color components in the RGB8 space, in a convenient "RRGGBB" hex string β€” likely to be useful HTML, or other similar places. drop it straight into your css and she'll simply serve. πŸ’…

🌸 alpha_blend

$mix = $color->alpha_blend( $other, [ $alpha ] );

Return a new color which is a blended combination of the two passed into it. The optional $alpha parameter defines the mix ratio between the two colors, defaulting to 0.5 if not defined. Values closer to 0 will blend more of $color; values closer to 1 will blend more of $other. so like, the slider goes from "this one" to "that one" and 0.5 is the perfect little fifty-fifty moment. ✨

🌸 alpha8_blend

$mix = $color->alpha8_blend( $other, [ $alpha ] );

Similar to "alpha_blend" but works with integer arithmetic. $alpha should be an integer in the range 0 to 255. whole numbers only bestie, she's not doing decimals today. 🧚

🌸 dst_rgb8

$measure = $color->dst_rgb8( $other );

Return a measure of the distance between the two colors. This is the unweighted Euclidean distance of the three color components. Two identical colors will have a measure of 0, pure black and pure white have a distance of 1, and all others will lie somewhere inbetween. measuring how far apart two colors are, emotionally and mathematically. 😭

🌸 dst_rgb8_cheap

$measure = $color->dst_rgb8_cheap( $other );

Return a measure of the distance between the two colors. This is the sum of the squares of the differences of each of the color components. This is part of the value used to calculate "dst_rgb8", but since it involves no square root it will be cheaper to calculate β€” perfect for when only the relative values matter, such as when picking the "best match" out of a set of colors. It ranges between 0 for identical colours and 3*(255^2) for the distance between pure black and pure white. same energy, less math, fewer tears. πŸ’€

✨ SEE ALSO ✨

  • Convert::Color β€” color space conversions

that's the whole family tree, go say hi. πŸ¦‹

✨ AUTHOR ✨

Paul Evans <leonerd@leonerd.org.uk> β€” the actual genius behind all of this. we stan. πŸ‘‘


no cap bestie, every flag, default, range and formula up there is exactly as the original wrote it β€” I just put it in cuter font. πŸ’–

this has been your girl, signing off β€” page from perl v5.40.0, dated 2024-09-16, Conver...::RGB8(3pm), the manual page of the century. mwah. πŸ’‹

πŸ“¦ where this page comes from