1Convert::Color::RGB(3)User Contributed Perl DocumentationConvert::Color::RGB(3)
2
3
4
6 "Convert::Color::RGB" - a color value represented as red/green/blue
7
9 Directly:
10
11 use Convert::Color::RGB;
12
13 my $red = Convert::Color::RGB->new( 1, 0, 0 );
14
15 # Can also parse strings
16 my $pink = Convert::Color::RGB->new( '1,0.7,0.7' );
17
18 Via Convert::Color:
19
20 use Convert::Color;
21
22 my $cyan = Convert::Color->new( 'rgb:0,1,1' );
23
25 Objects in this class represent a color in RGB space, as a set of three
26 floating-point values in the range 0 to 1.
27
28 For representations using 8- or 16-bit integers, see
29 Convert::Color::RGB8 and Convert::Color::RGB16.
30
32 new
33 $color = Convert::Color::RGB->new( $red, $green, $blue )
34
35 Returns a new object to represent the set of values given. These values
36 should be floating-point numbers between 0 and 1. Values outside of
37 this range will be clamped.
38
39 $color = Convert::Color::RGB->new( $string )
40
41 Parses $string for values, and construct a new object similar to the
42 above three-argument form. The string should be in the form
43
44 red,green,blue
45
46 containing the three floating-point values in decimal notation.
47
49 red
50 $r = $color->red
51
52 green
53 $g = $color->green
54
55 blue
56 $b = $color->blue
57
58 Accessors for the three components of the color.
59
60 rgb
61 ( $red, $green, $blue ) = $color->rgb
62
63 Returns the individual red, green and blue color components of the
64 color value.
65
66 alpha_blend
67 $mix = $color->alpha_blend( $other, [ $alpha ] )
68
69 Return a new color which is a blended combination of the two passed
70 into it. The optional $alpha parameter defines the mix ratio between
71 the two colors, defaulting to 0.5 if not defined. Values closer to 0
72 will blend more of $color, closer to 1 will blend more of $other.
73
74 dst_rgb
75 $measure = $color->dst_rgb( $other )
76
77 Return a measure of the distance between the two colors. This is the
78 unweighted Euclidean distance of the three color components. Two
79 identical colors will have a measure of 0, pure black and pure white
80 have a distance of 1, and all others will lie somewhere inbetween.
81
82 dst_rgb_cheap
83 $measure = $color->dst_rgb_cheap( $other )
84
85 Return a measure of the distance between the two colors. This is the
86 sum of the squares of the differences of each of the color components.
87 This is part of the value used to calculate "dst_rgb", but since it
88 involves no square root it will be cheaper to calculate, for use in
89 cases where only the relative values matter, such as when picking the
90 "best match" out of a set of colors. It ranges between 0 for identical
91 colours and 3 for the distance between pure black and pure white.
92
94 Generating Gradients
95 The "alpha_blend" method can be used to generate a smooth gradient
96 between two colours.
97
98 use Convert::Color;
99
100 my $blue = Convert::Color->new("vga:blue");
101 my $cyan = Convert::Color->new("vga:cyan");
102
103 say $blue->alpha_blend( $cyan, $_/10 )->as_rgb8->hex for 0 .. 10
104
106 • Convert::Color - color space conversions
107
108 • Convert::Color::HSV - a color value represented as
109 hue/saturation/value
110
111 • Convert::Color::HSL - a color value represented as
112 hue/saturation/lightness
113
115 Paul Evans <leonerd@leonerd.org.uk>
116
117
118
119perl v5.36.0 2022-07-22 Convert::Color::RGB(3)