| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Graphics::Color::HSL; |
|
2
|
|
|
|
|
|
|
$Graphics::Color::HSL::VERSION = '0.31'; |
|
3
|
1
|
|
|
1
|
|
16506
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use MooseX::Aliases; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends qw(Graphics::Color); |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: HSL color space |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Graphics::Color::Equal'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Graphics::Color::Types qw(Number360OrLess NumberOneOrLess); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'hue' => ( |
|
16
|
|
|
|
|
|
|
is => 'rw', |
|
17
|
|
|
|
|
|
|
isa => Number360OrLess, |
|
18
|
|
|
|
|
|
|
default => 1, |
|
19
|
|
|
|
|
|
|
alias => 'h' |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'saturation' => ( |
|
24
|
|
|
|
|
|
|
is => 'rw', |
|
25
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
|
26
|
|
|
|
|
|
|
default => 1, |
|
27
|
|
|
|
|
|
|
alias => 's' |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has 'lightness' => ( |
|
32
|
|
|
|
|
|
|
is => 'rw', |
|
33
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
|
34
|
|
|
|
|
|
|
default => 1, |
|
35
|
|
|
|
|
|
|
alias => 'l' |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has 'alpha' => ( |
|
40
|
|
|
|
|
|
|
is => 'rw', |
|
41
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
|
42
|
|
|
|
|
|
|
default => 1, |
|
43
|
|
|
|
|
|
|
alias => 'a' |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has 'name' => ( is => 'rw', isa => 'Str' ); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub as_string { |
|
51
|
|
|
|
|
|
|
my ($self) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return sprintf('%d,%0.2f,%0.2f,%0.2f', |
|
54
|
|
|
|
|
|
|
$self->hue, $self->saturation, $self->lightness, $self->alpha |
|
55
|
|
|
|
|
|
|
); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub as_percent_string { |
|
60
|
|
|
|
|
|
|
my ($self) = @_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return sprintf("%d, %d%%, %d%%, %0.2f", |
|
63
|
|
|
|
|
|
|
$self->hue, $self->saturation * 100, $self->lightness * 100, |
|
64
|
|
|
|
|
|
|
$self->alpha |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub as_array { |
|
70
|
|
|
|
|
|
|
my ($self) = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return ($self->hue, $self->saturation, $self->lightness); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub as_array_with_alpha { |
|
77
|
|
|
|
|
|
|
my ($self) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return ($self->hue, $self->saturation, $self->lightness, $self->alpha); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub equal_to { |
|
84
|
|
|
|
|
|
|
my ($self, $other) = @_; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return 0 unless defined($other); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
unless($self->hue == $other->hue) { |
|
89
|
|
|
|
|
|
|
return 0; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
unless($self->saturation == $other->saturation) { |
|
92
|
|
|
|
|
|
|
return 0; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
unless($self->lightness == $other->lightness) { |
|
95
|
|
|
|
|
|
|
return 0; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
unless($self->alpha == $other->alpha) { |
|
98
|
|
|
|
|
|
|
return 0; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return 1; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
no Moose; |
|
107
|
|
|
|
|
|
|
1; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=pod |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Graphics::Color::HSL - HSL color space |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
version 0.31 |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
use Graphics::Color::HSL; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $color = Graphics::Color::HSL->new({ |
|
126
|
|
|
|
|
|
|
hue => 120, |
|
127
|
|
|
|
|
|
|
saturation => .5, |
|
128
|
|
|
|
|
|
|
lightness => .25, |
|
129
|
|
|
|
|
|
|
}); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Graphics::Color::HSL represents a Color in an RGB color space. HSL stands for |
|
134
|
|
|
|
|
|
|
B<Hue> B<Saturation> and B<Lightness>. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 hue |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 h |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Set/Get the hue component of this Color. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 saturation |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 s |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Set/Get the saturation component of this Color. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 lightness |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 l |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Set/Get the lightness component of this Color. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 alpha |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Set/Get the alpha component of this Color. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 name |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Get the name of this color. Only valid if the color was created by name. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 METHODS |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 as_string |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Get a string version of this Color in the form of: |
|
169
|
|
|
|
|
|
|
HUE,SATURATION,LIGHTNESS,ALPHA |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 as_percent_string |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Return a percent formatted value for this color. This format is suitable for |
|
174
|
|
|
|
|
|
|
CSS HSL values. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 as_array |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Get the HSL values as an array |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 as_array_with_alpha |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Get the HSLA values as an array |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 equal_to |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Compares this color to the provided one. Returns 1 if true, else 0; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 not_equal_to |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
The opposite of equal_to. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 AUTHOR |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Cory G Watson <gphat@cpan.org> |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Cold Hard Code, LLC. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
201
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |