Conver...or::RGB(3pm)
π Convert::Color::RGB β the pink one (3pm) π
okay bestie so this is a User Contributed Perl Documentation page, and it's giving "my color is a color" realness π
This is Convert::Color::RGB, no cap, and it's literally just a color value represented as red/green/blue π
β¨ NAME β¨
"Convert::Color::RGB" β a color value represented as red/green/blue π¦
π SYNOPSIS π
Directly, like, the most straightforward way:
use Convert::Color::RGB;
my $red = Convert::Color::RGB->new( 1, 0, 0 );
# Can also parse strings
my $pink = Convert::Color::RGB->new( '1,0.7,0.7' );
Or via Convert::Color, if you wanna be, you know, indirect about it:
use Convert::Color;
my $cyan = Convert::Color->new( 'rgb:0,1,1' );
π DESCRIPTION π
So the objects in this class represent a color in RGB space, and it's literally just a set of three floating-point values in the range 0 to 1. That's it, that's the whole vibe πΈ
Now β for representations using 8- or 16-bit integers, you're gonna wanna go see Convert::Color::RGB8 and Convert::Color::RGB16 instead. Different girls, different lore π
π CONSTRUCTOR π
π
new
$color = Convert::Color::RGB->new( $red, $green, $blue );
Returns a new object representing the set of values you gave it π«Ά These values should be floating-point numbers between 0 and 1. And if you go outside that range? β οΈ Not a vibe β the values will be clamped.
bestie, clamping means it gets squished back into range. it does NOT error out. it just quietly fixes your nonsense π
There's also this form:
$color = Convert::Color::RGB->new( $string );
This one parses $string for values and makes a new object just like the three-argument form above π The string needs to be in the form:
red,green,blue
containing the three floating-point values in decimal notation. periodt β¨
π¦ METHODS π¦
πΈ red
$r = $color->red;
πΈ green
$g = $color->green;
πΈ blue
$b = $color->blue;
Accessors for the three components of the color π one for each, as the universe intended.
β¨ rgb
( $red, $green, $blue ) = $color->rgb;
Returns the individual red, green and blue color components of the color value π all three at once, in a cute lil list.
π 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, and it defaults to 0.5 if not defined. Values closer to 0 will blend more of $color, and closer to 1 will blend more of $other π«Ά literally the slay button for gradients, iykyk.
π dst_rgb
$measure = $color->dst_rgb( $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 π«
π§ dst_rgb_cheap
$measure = $color->dst_rgb_cheap( $other );
Return a measure of the distance between the two colors π
This one is the sum of the squares of the differences of each of the color components. It's part of the value used to calculate "dst_rgb", but since it involves no square root it will be cheaper to calculate β so use it in cases where only the relative values matter, like when you're picking the "best match" out of a set of colors π
It ranges between 0 for identical colours and 3 for the distance between pure black and pure white π no square roots, no stress, we love a budget queen.
π EXAMPLES π
π Generating Gradients
The "alpha_blend" method can be used to generate a smooth gradient between two colours πΈ iconic behaviour, honestly:
use Convert::Color;
my $blue = Convert::Color->new("vga:blue");
my $cyan = Convert::Color->new("vga:cyan");
say $blue->alpha_blend( $cyan, $_/10 )->as_rgb8->hex for 0 .. 10
π SEE ALSO π
Convert::Colorβ color space conversions π«Convert::Color::HSVβ a color value represented as hue/saturation/value πConvert::Color::HSLβ a color value represented as hue/saturation/lightness πΈ
π«Ά AUTHOR π«Ά
Paul Evans <leonerd@leonerd.org.uk> β thank you king π
so yeah, that's the whole page bestie, and lemme tell you the receipts: this was perl v5.40.0, dated 2024-09-16, and it lives in the Conver...or::RGB(3pm) section of your friendly neighborhood manual π go forth and blend ur colors, you got this β¨π π
π¦ where this page comes from
- ubuntu resolute: libconvert-color-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libconvert-color-perl 0.18-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