1Convert::Color::RGB(3)User Contributed Perl DocumentationConvert::Color::RGB(3)
2
3
4

NAME

6       "Convert::Color::RGB" - a color value represented as red/green/blue
7

SYNOPSIS

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

DESCRIPTION

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

CONSTRUCTOR

32   $color = Convert::Color::RGB->new( $red, $green, $blue )
33       Returns a new object to represent the set of values given. These values
34       should be floating-point numbers between 0 and 1. Values outside of
35       this range will be clamped.
36
37   $color = Convert::Color::RGB->new( $string )
38       Parses $string for values, and construct a new object similar to the
39       above three-argument form. The string should be in the form
40
41        red,green,blue
42
43       containing the three floating-point values in decimal notation.
44

METHODS

46   $r = $color->red
47   $g = $color->green
48   $b = $color->blue
49       Accessors for the three components of the color.
50
51   ( $red, $green, $blue ) = $color->rgb
52       Returns the individual red, green and blue color components of the
53       color value.
54
55   $mix = $color->alpha_blend( $other, [ $alpha ] )
56       Return a new color which is a blended combination of the two passed
57       into it.  The optional $alpha parameter defines the mix ratio between
58       the two colors, defaulting to 0.5 if not defined. Values closer to 0
59       will blend more of $color, closer to 1 will blend more of $other.
60
61   $measure = $color->dst_rgb( $other )
62       Return a measure of the distance between the two colors. This is the
63       unweighted Euclidean distance of the three color components. Two
64       identical colors will have a measure of 0, pure black and pure white
65       have a distance of 1, and all others will lie somewhere inbetween.
66
67   $measure = $color->dst_rgb_cheap( $other )
68       Return a measure of the distance between the two colors. This is the
69       sum of the squares of the differences of each of the color components.
70       This is part of the value used to calculate "dst_rgb", but since it
71       involves no square root it will be cheaper to calculate, for use in
72       cases where only the relative values matter, such as when picking the
73       "best match" out of a set of colors.  It ranges between 0 for identical
74       colours and 3 for the distance between pure black and pure white.
75

EXAMPLES

77   Generating Gradients
78       The "alpha_blend" method can be used to generate a smooth gradient
79       between two colours.
80
81        use Convert::Color;
82
83        my $blue = Convert::Color->new("vga:blue");
84        my $cyan = Convert::Color->new("vga:cyan");
85
86        say $blue->alpha_blend( $cyan, $_/10 )->as_rgb8->hex for 0 .. 10
87

SEE ALSO

89       ·   Convert::Color - color space conversions
90
91       ·   Convert::Color::HSV - a color value represented as
92           hue/saturation/value
93
94       ·   Convert::Color::HSL - a color value represented as
95           hue/saturation/lightness
96

AUTHOR

98       Paul Evans <leonerd@leonerd.org.uk>
99
100
101
102perl v5.30.1                      2020-01-29            Convert::Color::RGB(3)
Impressum