| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Graphics::Colourset; |
|
2
|
2
|
|
|
2
|
|
36557
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
55
|
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
132
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Graphics::Colourset - create sets of colours. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
This describes version B<0.02> of Graphics::Colourset. |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Graphics::Colourset; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $cs1 = Graphics::Colourset->new(hue=>60, shade=>1); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $col_str = $cs1->as_hex_string('foreground'); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $cs2 = $cs1->new_alt_colourset(shade=>4); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @colsets = $cs1->new_alt_coloursets(3); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module generates the colour definitions of a set of colours |
|
32
|
|
|
|
|
|
|
suitable for using as the basis of a colour-scheme for an X-Windows |
|
33
|
|
|
|
|
|
|
window-manager. They can also be used for CSS colour descriptions for |
|
34
|
|
|
|
|
|
|
Web-pages. The colours are defined as the usual "hex string", |
|
35
|
|
|
|
|
|
|
or as the more recent "rgb string". |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The aim of this is to avoid having to generate harmonious colour schemes |
|
38
|
|
|
|
|
|
|
by hand but to input a minimum number of parameters and to create all |
|
39
|
|
|
|
|
|
|
the colours from that. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DETAILS |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 Coloursets |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
A "colourset" is a set of five colours, suitable for defining one type |
|
46
|
|
|
|
|
|
|
of component in a window-manager or web-site "theme" or "colour scheme". |
|
47
|
|
|
|
|
|
|
All colours in a colourset have the same hue, but have different |
|
48
|
|
|
|
|
|
|
saturation and value (different "strengths") in keeping with their |
|
49
|
|
|
|
|
|
|
different roles. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
They are oriented towards being used for generating colours for buttons |
|
52
|
|
|
|
|
|
|
and borders. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item background |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The background colour is the main colour of the colourset, to be used |
|
59
|
|
|
|
|
|
|
for the background of the "component" (whatever that may be). |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item topshadow |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
The topshadow colour is a colour slightly lighter than the background |
|
64
|
|
|
|
|
|
|
colour, suitable for using to define a "top shadow" colour. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item bottomshadow |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The bottomshadow colour is a colour slightly darker than the background |
|
69
|
|
|
|
|
|
|
colour, suitable for using to define a "bottom shadow" colour. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item foreground |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The foreground colour is the colour designated to be used for the |
|
74
|
|
|
|
|
|
|
foreground, for text and the like. It is either much lighter or much |
|
75
|
|
|
|
|
|
|
darker than the background colour, in order to contrast suitably. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item foreground_inactive |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The "inactive" foreground colour is a colour which is intended to be |
|
80
|
|
|
|
|
|
|
used for things which are "greyed out", or not active. It is a colour |
|
81
|
|
|
|
|
|
|
which contrasts with the background, but not as much as the "foreground" |
|
82
|
|
|
|
|
|
|
colour. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=back |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
There are two parameters which determine the colours of a colourset. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item hue |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The hue in a 360 degree colour wheel. As a special tweak, if the hue |
|
93
|
|
|
|
|
|
|
equals 360, it is taken to be no hue at all (grey). This doesn't |
|
94
|
|
|
|
|
|
|
actually lose any hues, since 360 is normally exactly the same as zero |
|
95
|
|
|
|
|
|
|
(red). |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item shade |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The general "lightness" of the background. This is a range from 1 to 4, with 1 |
|
100
|
|
|
|
|
|
|
being the darkest and 4 being the lightest. This also determines the |
|
101
|
|
|
|
|
|
|
foreground colour, since a dark background will need a light foreground and |
|
102
|
|
|
|
|
|
|
visa-versa. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
If the shade is outside this range, a random shade will be picked. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 Base and Alternative Coloursets |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The "base" colourset is considered to be the main colourset; additional |
|
111
|
|
|
|
|
|
|
coloursets can be generated which are related to the base colourset in a |
|
112
|
|
|
|
|
|
|
contrasting-but-harmonious way. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
One test for the harmoniousness is to compare two coloursets and decide |
|
115
|
|
|
|
|
|
|
whether they would be "ugly" together. This is done in a rule-of-thumb |
|
116
|
|
|
|
|
|
|
way, which isn't perfect. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
|
|
|
|
|
|
|
|
120
|
2
|
|
|
2
|
|
2085
|
use Graphics::ColorObject; |
|
|
2
|
|
|
|
|
135624
|
|
|
|
2
|
|
|
|
|
5558
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 CLASS METHODS |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 new |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Create a new colourset, given an input hue, and foreground/background |
|
127
|
|
|
|
|
|
|
disposition. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$my colset = Graphics::Colourset->new( |
|
130
|
|
|
|
|
|
|
hue=>$hue, |
|
131
|
|
|
|
|
|
|
shade=>1, |
|
132
|
|
|
|
|
|
|
); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub new { |
|
137
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
138
|
0
|
|
|
|
|
|
my %parameters = @_; |
|
139
|
0
|
|
0
|
|
|
|
my $self = bless ({%parameters}, ref ($class) || $class); |
|
140
|
0
|
|
0
|
|
|
|
$self->{hue} ||= 0; |
|
141
|
0
|
0
|
|
|
|
|
$self->{shade} = 0 if !defined $self->{shade}; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
0
|
0
|
|
|
|
if ($self->{shade} < 1 or $self->{shade} > 4) |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
0
|
|
|
|
|
|
$self->{shade} = int(rand(4)) + 1; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
if ($self->{hue} == 360) # make it grey |
|
149
|
|
|
|
|
|
|
{ |
|
150
|
0
|
0
|
|
|
|
|
if ($self->{shade} == 1) # darkest |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
{ |
|
152
|
|
|
|
|
|
|
$self->{foreground} = |
|
153
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.99]); |
|
154
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
155
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.70]); |
|
156
|
|
|
|
|
|
|
$self->{background} = |
|
157
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.20]); |
|
158
|
|
|
|
|
|
|
$self->{topshadow} = |
|
159
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.30]); |
|
160
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
161
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.10]); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
elsif ($self->{shade} == 2) |
|
164
|
|
|
|
|
|
|
{ |
|
165
|
|
|
|
|
|
|
$self->{foreground} = |
|
166
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.95]); |
|
167
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
168
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.80]); |
|
169
|
|
|
|
|
|
|
$self->{background} = |
|
170
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.50]); |
|
171
|
|
|
|
|
|
|
$self->{topshadow} = |
|
172
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.70]); |
|
173
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
174
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.30]); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
elsif ($self->{shade} == 3) |
|
177
|
|
|
|
|
|
|
{ |
|
178
|
|
|
|
|
|
|
$self->{foreground} = |
|
179
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.05]); |
|
180
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
181
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.60]); |
|
182
|
|
|
|
|
|
|
$self->{background} = |
|
183
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.75]); |
|
184
|
|
|
|
|
|
|
$self->{topshadow} = |
|
185
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.85]); |
|
186
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
187
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.65]); |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
elsif ($self->{shade} == 4) # lightest |
|
190
|
|
|
|
|
|
|
{ |
|
191
|
|
|
|
|
|
|
$self->{foreground} = |
|
192
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.20]); |
|
193
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
194
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.55]); |
|
195
|
|
|
|
|
|
|
$self->{background} = |
|
196
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.88]); |
|
197
|
|
|
|
|
|
|
$self->{topshadow} = |
|
198
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.96]); |
|
199
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
200
|
0
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([0, 0, 0.78]); |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
else # coloured |
|
204
|
|
|
|
|
|
|
{ |
|
205
|
0
|
0
|
|
|
|
|
if ($self->{shade} == 1) # darkest |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
{ |
|
207
|
|
|
|
|
|
|
$self->{foreground} = |
|
208
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
209
|
0
|
|
|
|
|
|
0.10, 0.99]); |
|
210
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
211
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
212
|
0
|
|
|
|
|
|
0.30, 0.80]); |
|
213
|
|
|
|
|
|
|
$self->{background} = |
|
214
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
215
|
0
|
|
|
|
|
|
0.90, 0.35]); |
|
216
|
|
|
|
|
|
|
$self->{topshadow} = |
|
217
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
218
|
0
|
|
|
|
|
|
0.50, 0.45]); |
|
219
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
220
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
221
|
0
|
|
|
|
|
|
0.90, 0.25]); |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
elsif ($self->{shade} == 2) |
|
224
|
|
|
|
|
|
|
{ |
|
225
|
|
|
|
|
|
|
$self->{foreground} = |
|
226
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
227
|
0
|
|
|
|
|
|
0, 0.99]); |
|
228
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
229
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
230
|
0
|
|
|
|
|
|
0.30, 0.90]); |
|
231
|
|
|
|
|
|
|
$self->{background} = |
|
232
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
233
|
0
|
|
|
|
|
|
0.80, 0.50]); |
|
234
|
|
|
|
|
|
|
$self->{topshadow} = |
|
235
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
236
|
0
|
|
|
|
|
|
0.50, 0.65]); |
|
237
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
238
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
239
|
0
|
|
|
|
|
|
0.80, 0.45]); |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
elsif ($self->{shade} == 3) |
|
242
|
|
|
|
|
|
|
{ |
|
243
|
0
|
0
|
0
|
|
|
|
if ($self->{hue} > 220 && $self->{hue} < 280) |
|
244
|
|
|
|
|
|
|
{ |
|
245
|
|
|
|
|
|
|
# blue/purple are too dark to deal with this |
|
246
|
|
|
|
|
|
|
$self->{foreground} = |
|
247
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
248
|
0
|
|
|
|
|
|
0.99, 0.05]); |
|
249
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
250
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
251
|
0
|
|
|
|
|
|
0.90, 0.60]); |
|
252
|
|
|
|
|
|
|
$self->{background} = |
|
253
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
254
|
0
|
|
|
|
|
|
0.50, 0.85]); |
|
255
|
|
|
|
|
|
|
$self->{topshadow} = |
|
256
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
257
|
0
|
|
|
|
|
|
0.50, 0.95]); |
|
258
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
259
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
260
|
0
|
|
|
|
|
|
0.70, 0.75]); |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
else |
|
263
|
|
|
|
|
|
|
{ |
|
264
|
|
|
|
|
|
|
$self->{foreground} = |
|
265
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
266
|
0
|
|
|
|
|
|
0.99, 0.05]); |
|
267
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
268
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
269
|
0
|
|
|
|
|
|
0.90, 0.60]); |
|
270
|
|
|
|
|
|
|
$self->{background} = |
|
271
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
272
|
0
|
|
|
|
|
|
0.75, 0.75]); |
|
273
|
|
|
|
|
|
|
$self->{topshadow} = |
|
274
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
275
|
0
|
|
|
|
|
|
0.45, 0.85]); |
|
276
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
277
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
278
|
0
|
|
|
|
|
|
0.70, 0.65]); |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
} |
|
281
|
|
|
|
|
|
|
elsif ($self->{shade} == 4) # lightest |
|
282
|
|
|
|
|
|
|
{ |
|
283
|
|
|
|
|
|
|
$self->{foreground} = |
|
284
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
285
|
0
|
|
|
|
|
|
0.90, 0.20]); |
|
286
|
|
|
|
|
|
|
$self->{foreground_inactive} = |
|
287
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
288
|
0
|
|
|
|
|
|
0.40, 0.55]); |
|
289
|
|
|
|
|
|
|
$self->{background} = |
|
290
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
291
|
0
|
|
|
|
|
|
0.30, 0.92]); |
|
292
|
|
|
|
|
|
|
$self->{topshadow} = |
|
293
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
294
|
0
|
|
|
|
|
|
0.20, 0.97]); |
|
295
|
|
|
|
|
|
|
$self->{bottomshadow} = |
|
296
|
|
|
|
|
|
|
Graphics::ColorObject->new_HSV([$self->{hue}, |
|
297
|
0
|
|
|
|
|
|
0.40, 0.75]); |
|
298
|
|
|
|
|
|
|
} |
|
299
|
|
|
|
|
|
|
} |
|
300
|
0
|
|
|
|
|
|
return ($self); |
|
301
|
|
|
|
|
|
|
} # new |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head2 make_n_coloursets |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
my @colsets = Graphics::Colourset::make_n_coloursets(number=>$num, |
|
306
|
|
|
|
|
|
|
shades=>[1,0,3,4], |
|
307
|
|
|
|
|
|
|
hues=>[10,50,undef,undef]); |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
Make $num coloursets, based on the given shades and hues; if a shade is |
|
310
|
|
|
|
|
|
|
zero or undef, a random shade will be chosen; if a hue is undef, a random |
|
311
|
|
|
|
|
|
|
hue will be chosen. The coloursets will be generated, but checked with |
|
312
|
|
|
|
|
|
|
is_ugly to ensure that it isn't ugly. They will also be checked to make |
|
313
|
|
|
|
|
|
|
sure that they aren't the same as the other coloursets. |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
Note that larger numbers will take longer and be more difficult to generate. |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=cut |
|
318
|
|
|
|
|
|
|
sub make_n_coloursets { |
|
319
|
0
|
|
|
0
|
1
|
|
my %args = ( |
|
320
|
|
|
|
|
|
|
number=>1, |
|
321
|
|
|
|
|
|
|
shades=>undef, |
|
322
|
|
|
|
|
|
|
hues=>undef, |
|
323
|
|
|
|
|
|
|
@_ |
|
324
|
|
|
|
|
|
|
); |
|
325
|
|
|
|
|
|
|
|
|
326
|
0
|
|
|
|
|
|
my @colsets = (); |
|
327
|
0
|
|
|
|
|
|
while (!@colsets) |
|
328
|
|
|
|
|
|
|
{ |
|
329
|
0
|
|
|
|
|
|
@colsets = attempt_n_coloursets(%args); |
|
330
|
|
|
|
|
|
|
} |
|
331
|
0
|
|
|
|
|
|
return @colsets; |
|
332
|
|
|
|
|
|
|
} # make_n_coloursets |
|
333
|
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=head2 attempt_n_coloursets |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
my @colsets = Graphics::Colourset::make_n_coloursets(number=>$num, |
|
337
|
|
|
|
|
|
|
shades=>[1,0,3,4], |
|
338
|
|
|
|
|
|
|
hues=>[10,50,undef,undef]); |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
Make $num coloursets, based on the given shades and hues; if a shade is |
|
341
|
|
|
|
|
|
|
zero or undef, a random shade will be chosen; if a hue is undef, a random |
|
342
|
|
|
|
|
|
|
hue will be chosen. The coloursets will be generated, but checked with |
|
343
|
|
|
|
|
|
|
is_ugly to ensure that it isn't ugly. They will also be checked to make |
|
344
|
|
|
|
|
|
|
sure that they aren't the same as the other coloursets. |
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
If a colourset is ugly, an empty set is returned. |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
Note that larger numbers will take longer and be more difficult to generate. |
|
349
|
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
=cut |
|
351
|
|
|
|
|
|
|
sub attempt_n_coloursets { |
|
352
|
0
|
|
|
0
|
1
|
|
my %args = ( |
|
353
|
|
|
|
|
|
|
number=>1, |
|
354
|
|
|
|
|
|
|
shades=>undef, |
|
355
|
|
|
|
|
|
|
hues=>undef, |
|
356
|
|
|
|
|
|
|
@_ |
|
357
|
|
|
|
|
|
|
); |
|
358
|
|
|
|
|
|
|
|
|
359
|
0
|
|
|
|
|
|
my $num_colsets = $args{number}; |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# set an array of shades; by default zero means random |
|
362
|
0
|
|
|
|
|
|
my @shades = (); |
|
363
|
0
|
|
|
|
|
|
for (my $i = 0; $i < $num_colsets; $i++) |
|
364
|
|
|
|
|
|
|
{ |
|
365
|
0
|
|
|
|
|
|
$shades[$i] = 0; |
|
366
|
|
|
|
|
|
|
} |
|
367
|
|
|
|
|
|
|
# if shades are passed in, use them |
|
368
|
0
|
0
|
|
|
|
|
if (defined $args{shades}) |
|
369
|
|
|
|
|
|
|
{ |
|
370
|
0
|
|
|
|
|
|
for (my $i = 0; $i < @{$args{shades}}; $i++) |
|
|
0
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
{ |
|
372
|
0
|
|
|
|
|
|
$shades[$i] = $args{shades}->[$i]; |
|
373
|
|
|
|
|
|
|
} |
|
374
|
|
|
|
|
|
|
} |
|
375
|
|
|
|
|
|
|
# set an array of hues; by default undefined means random |
|
376
|
0
|
|
|
|
|
|
my @hues = (); |
|
377
|
0
|
|
|
|
|
|
for (my $i = 0; $i < $num_colsets; $i++) |
|
378
|
|
|
|
|
|
|
{ |
|
379
|
0
|
|
|
|
|
|
$hues[$i] = undef; |
|
380
|
|
|
|
|
|
|
} |
|
381
|
|
|
|
|
|
|
# if hues are passed in, use them |
|
382
|
0
|
0
|
|
|
|
|
if (defined $args{hues}) |
|
383
|
|
|
|
|
|
|
{ |
|
384
|
0
|
|
|
|
|
|
for (my $i = 0; $i < @{$args{hues}}; $i++) |
|
|
0
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
{ |
|
386
|
0
|
|
|
|
|
|
$hues[$i] = $args{hues}->[$i]; |
|
387
|
|
|
|
|
|
|
} |
|
388
|
|
|
|
|
|
|
} |
|
389
|
|
|
|
|
|
|
|
|
390
|
0
|
|
|
|
|
|
my @styles = qw(complement splitcomp triad tetrad analog); |
|
391
|
0
|
|
|
|
|
|
my %intervals = ( |
|
392
|
|
|
|
|
|
|
complement=>[0, 180], |
|
393
|
|
|
|
|
|
|
splitcomp=>[0, 180-24, 180+24], |
|
394
|
|
|
|
|
|
|
triad=>[0, 120, 240], |
|
395
|
|
|
|
|
|
|
tetrad=>[0, 90, 180, 240], |
|
396
|
|
|
|
|
|
|
analog=>[0, -30, 30, -60, 60], |
|
397
|
|
|
|
|
|
|
mono=>[0, 0, 0, 0], |
|
398
|
|
|
|
|
|
|
); |
|
399
|
|
|
|
|
|
|
# add mono to the styles if there are few enough coloursets |
|
400
|
0
|
0
|
|
|
|
|
if ($num_colsets <= @{$intervals{mono}}) |
|
|
0
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
{ |
|
402
|
0
|
|
|
|
|
|
push @styles, 'mono'; |
|
403
|
|
|
|
|
|
|
} |
|
404
|
|
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
my $style = $styles[int(rand(@styles))]; |
|
406
|
0
|
|
|
|
|
|
my $num_intervals = @{$intervals{$style}}; |
|
|
0
|
|
|
|
|
|
|
|
407
|
0
|
|
|
|
|
|
print STDERR "style:$style, num_intervals:$num_intervals\n"; |
|
408
|
0
|
0
|
|
|
|
|
if ($style eq 'mono') |
|
409
|
|
|
|
|
|
|
{ |
|
410
|
|
|
|
|
|
|
# set the shades for mono, dark to light |
|
411
|
0
|
|
|
|
|
|
for (my $i = 0; $i < $num_colsets; $i++) |
|
412
|
|
|
|
|
|
|
{ |
|
413
|
0
|
|
|
|
|
|
$shades[$i] = $i + 1; |
|
414
|
|
|
|
|
|
|
} |
|
415
|
|
|
|
|
|
|
} |
|
416
|
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
|
my @colsets = (); |
|
418
|
0
|
0
|
|
|
|
|
my $basehue = (defined $hues[0] ? $hues[0] : int(rand(360))); |
|
419
|
|
|
|
|
|
|
|
|
420
|
0
|
|
|
|
|
|
while (@colsets < $num_colsets) |
|
421
|
|
|
|
|
|
|
{ |
|
422
|
0
|
|
|
|
|
|
my $next_cs; |
|
423
|
|
|
|
|
|
|
# get the index of the next colset |
|
424
|
0
|
|
|
|
|
|
my $ind = @colsets; |
|
425
|
0
|
0
|
|
|
|
|
$shades[$ind] = int(rand(4)) + 1 if $shades[$ind] == 0; |
|
426
|
0
|
|
0
|
|
|
|
while ($ind >= $num_intervals |
|
427
|
|
|
|
|
|
|
and $shades[$ind] == $shades[$ind - $num_intervals]) |
|
428
|
|
|
|
|
|
|
{ |
|
429
|
0
|
|
|
|
|
|
$shades[$ind] = int(rand(4)) + 1; |
|
430
|
|
|
|
|
|
|
} |
|
431
|
0
|
|
|
|
|
|
my $shade = $shades[$ind]; |
|
432
|
0
|
|
|
|
|
|
my $hue = $hues[$ind]; |
|
433
|
0
|
0
|
|
|
|
|
if (!defined $hue) |
|
434
|
|
|
|
|
|
|
{ |
|
435
|
0
|
0
|
|
|
|
|
if ($ind < $num_intervals) |
|
436
|
|
|
|
|
|
|
{ |
|
437
|
0
|
|
|
|
|
|
$hue = $basehue + $intervals{$style}->[$ind]; |
|
438
|
|
|
|
|
|
|
} |
|
439
|
|
|
|
|
|
|
else |
|
440
|
|
|
|
|
|
|
{ |
|
441
|
0
|
|
|
|
|
|
$hue = $basehue + $intervals{$style}->[$ind % |
|
442
|
|
|
|
|
|
|
$num_intervals]; |
|
443
|
|
|
|
|
|
|
} |
|
444
|
0
|
0
|
|
|
|
|
$hue += 360 if ($hue < 0); |
|
445
|
0
|
0
|
|
|
|
|
$hue -= 360 if ($hue > 360); |
|
446
|
|
|
|
|
|
|
} |
|
447
|
0
|
|
|
|
|
|
print STDERR "[$ind] HUE: $hue, SHADE: $shade\n"; |
|
448
|
0
|
|
|
|
|
|
$next_cs = Graphics::Colourset->new(hue=>$hue, shade=>$shade); |
|
449
|
0
|
0
|
0
|
|
|
|
if ($ind > 0 and $next_cs->is_ugly($colsets[$ind - 1])) |
|
450
|
|
|
|
|
|
|
{ |
|
451
|
0
|
|
|
|
|
|
return (); |
|
452
|
|
|
|
|
|
|
} |
|
453
|
0
|
|
|
|
|
|
push @colsets, $next_cs; |
|
454
|
|
|
|
|
|
|
} |
|
455
|
|
|
|
|
|
|
|
|
456
|
0
|
|
|
|
|
|
return @colsets; |
|
457
|
|
|
|
|
|
|
} # attempt_n_coloursets |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
=head2 as_hex_string |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
my $colstr = $self->as_hex_string('foreground'); |
|
464
|
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
Return the given colour as a hex colour string |
|
466
|
|
|
|
|
|
|
such as #99FF00 |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=cut |
|
469
|
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
sub as_hex_string { |
|
471
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
472
|
0
|
|
|
|
|
|
my $colour = shift; |
|
473
|
|
|
|
|
|
|
|
|
474
|
0
|
|
|
|
|
|
my $hex = $self->{$colour}->as_RGBhex(); |
|
475
|
0
|
|
|
|
|
|
return "#$hex"; |
|
476
|
|
|
|
|
|
|
} # as_hex_string |
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
=head2 as_rgb_string |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
my $colstr = $self->as_rgb_string('foreground'); |
|
481
|
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
Return the given colour as an X colour string |
|
483
|
|
|
|
|
|
|
such as rgb:99/FF/00 |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
=cut |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
sub as_rgb_string { |
|
488
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
489
|
0
|
|
|
|
|
|
my $colour = shift; |
|
490
|
|
|
|
|
|
|
|
|
491
|
0
|
|
|
|
|
|
my ($r, $g, $b) = @{$self->{$colour}->as_RGB255()}; |
|
|
0
|
|
|
|
|
|
|
|
492
|
0
|
|
|
|
|
|
return sprintf("rgb:%02X/%02X/%02X", $r, $g, $b); |
|
493
|
|
|
|
|
|
|
} # as_rgb_string |
|
494
|
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
=head2 equals |
|
496
|
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
Checks if the given colourset equals the passed-in one. |
|
498
|
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
if ($colset->equals($other_colset)) |
|
500
|
|
|
|
|
|
|
{ |
|
501
|
|
|
|
|
|
|
... |
|
502
|
|
|
|
|
|
|
} |
|
503
|
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=cut |
|
505
|
|
|
|
|
|
|
sub equals { |
|
506
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
507
|
0
|
|
|
|
|
|
my $colset2 = shift; |
|
508
|
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
return ($self->{hue} == $colset2->{hue} |
|
510
|
0
|
|
0
|
|
|
|
&& $self->{shade} == $colset2->{shade}); |
|
511
|
|
|
|
|
|
|
} # equals |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
=head2 is_ugly |
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
my $ret = $colset1->is_ugly($colset2); |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
Compares two coloursets and declares whether they would be ugly |
|
518
|
|
|
|
|
|
|
together. This is naturally a subjective assessment on the part of |
|
519
|
|
|
|
|
|
|
the author, but hopefully helpful. |
|
520
|
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=cut |
|
522
|
|
|
|
|
|
|
sub is_ugly { |
|
523
|
0
|
|
|
0
|
1
|
|
my $colset1 = shift; |
|
524
|
0
|
|
|
|
|
|
my $colset2 = shift; |
|
525
|
|
|
|
|
|
|
|
|
526
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} == 360 |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
527
|
|
|
|
|
|
|
&& $colset2->{hue} >= 50 |
|
528
|
|
|
|
|
|
|
&& $colset2->{hue} <= 80) |
|
529
|
|
|
|
|
|
|
|| ($colset2->{hue} == 360 |
|
530
|
|
|
|
|
|
|
&& $colset1->{hue} >= 50 |
|
531
|
|
|
|
|
|
|
&& $colset1->{hue} <= 80)) |
|
532
|
|
|
|
|
|
|
{ |
|
533
|
|
|
|
|
|
|
# yellow doesn't go with grey |
|
534
|
0
|
|
|
|
|
|
return 1; |
|
535
|
|
|
|
|
|
|
} |
|
536
|
|
|
|
|
|
|
elsif (($colset1->{hue} == 360 |
|
537
|
|
|
|
|
|
|
&& $colset2->{hue} > 10 |
|
538
|
|
|
|
|
|
|
&& $colset2->{hue} < 50 |
|
539
|
|
|
|
|
|
|
&& $colset2->{shade} > 1) |
|
540
|
|
|
|
|
|
|
|| ($colset2->{hue} == 360 |
|
541
|
|
|
|
|
|
|
&& $colset1->{hue} > 10 |
|
542
|
|
|
|
|
|
|
&& $colset1->{hue} < 50 |
|
543
|
|
|
|
|
|
|
&& $colset1->{shade} > 1)) |
|
544
|
|
|
|
|
|
|
{ |
|
545
|
|
|
|
|
|
|
# orange only looks good if it's dark |
|
546
|
0
|
|
|
|
|
|
return 1; |
|
547
|
|
|
|
|
|
|
} |
|
548
|
|
|
|
|
|
|
elsif ($colset1->{hue} == 360 |
|
549
|
|
|
|
|
|
|
|| $colset2->{hue} == 360) |
|
550
|
|
|
|
|
|
|
{ |
|
551
|
|
|
|
|
|
|
# everything else goes with grey |
|
552
|
0
|
|
|
|
|
|
return 0; |
|
553
|
|
|
|
|
|
|
} |
|
554
|
|
|
|
|
|
|
# all colours within 30 degrees of each other look good |
|
555
|
0
|
|
|
|
|
|
my $hdiff = abs($colset1->{hue} - $colset2->{hue}); |
|
556
|
0
|
0
|
|
|
|
|
if ($hdiff <= 30) |
|
557
|
|
|
|
|
|
|
{ |
|
558
|
0
|
|
|
|
|
|
return 0; |
|
559
|
|
|
|
|
|
|
} |
|
560
|
|
|
|
|
|
|
|
|
561
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 0 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
562
|
|
|
|
|
|
|
&& $colset1->{hue} < 10 |
|
563
|
|
|
|
|
|
|
&& $colset1->{shade} == 4 |
|
564
|
|
|
|
|
|
|
&& $colset2->{hue} >= 60 |
|
565
|
|
|
|
|
|
|
&& $colset2->{hue} < 70 |
|
566
|
|
|
|
|
|
|
&& $colset2->{shade} != 4) |
|
567
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 0 |
|
568
|
|
|
|
|
|
|
&& $colset2->{hue} < 10 |
|
569
|
|
|
|
|
|
|
&& $colset2->{shade} == 4 |
|
570
|
|
|
|
|
|
|
&& $colset1->{hue} >= 60 |
|
571
|
|
|
|
|
|
|
&& $colset1->{hue} < 70 |
|
572
|
|
|
|
|
|
|
&& $colset1->{shade} != 4)) |
|
573
|
|
|
|
|
|
|
{ |
|
574
|
|
|
|
|
|
|
# rose doesn't go with yellow or green |
|
575
|
0
|
|
|
|
|
|
return 1; |
|
576
|
|
|
|
|
|
|
} |
|
577
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} > 10 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
578
|
|
|
|
|
|
|
&& $colset1->{hue} <= 40 |
|
579
|
|
|
|
|
|
|
&& $colset1->{shade} > 1 |
|
580
|
|
|
|
|
|
|
&& $colset1->{shade} < 4 |
|
581
|
|
|
|
|
|
|
&& $colset2->{hue} > 60 |
|
582
|
|
|
|
|
|
|
&& $colset2->{hue} <= 100) |
|
583
|
|
|
|
|
|
|
|| ($colset2->{hue} > 10 |
|
584
|
|
|
|
|
|
|
&& $colset2->{hue} <= 40 |
|
585
|
|
|
|
|
|
|
&& $colset2->{shade} > 1 |
|
586
|
|
|
|
|
|
|
&& $colset2->{shade} < 4 |
|
587
|
|
|
|
|
|
|
&& $colset1->{hue} > 60 |
|
588
|
|
|
|
|
|
|
&& $colset1->{hue} <= 100)) |
|
589
|
|
|
|
|
|
|
{ |
|
590
|
|
|
|
|
|
|
# orange doesn't go with green |
|
591
|
0
|
|
|
|
|
|
return 1; |
|
592
|
|
|
|
|
|
|
} |
|
593
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 270 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
594
|
|
|
|
|
|
|
&& $colset1->{hue} < 280 |
|
595
|
|
|
|
|
|
|
&& $colset2->{hue} >= 330 |
|
596
|
|
|
|
|
|
|
&& $colset2->{hue} < 340 |
|
597
|
|
|
|
|
|
|
&& $colset2->{shade} > 1) |
|
598
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 270 |
|
599
|
|
|
|
|
|
|
&& $colset2->{hue} < 280 |
|
600
|
|
|
|
|
|
|
&& $colset1->{hue} >= 330 |
|
601
|
|
|
|
|
|
|
&& $colset1->{hue} < 340 |
|
602
|
|
|
|
|
|
|
&& $colset1->{shade} > 1)) |
|
603
|
|
|
|
|
|
|
{ |
|
604
|
|
|
|
|
|
|
# purple doesn't go with pinky-red |
|
605
|
0
|
|
|
|
|
|
return 1; |
|
606
|
|
|
|
|
|
|
} |
|
607
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 280 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
608
|
|
|
|
|
|
|
&& $colset1->{hue} < 360 |
|
609
|
|
|
|
|
|
|
&& (($colset2->{hue} >= 340 |
|
610
|
|
|
|
|
|
|
&& $colset2->{hue} < 360) |
|
611
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 0 |
|
612
|
|
|
|
|
|
|
&& $colset2->{hue} < 50)) |
|
613
|
|
|
|
|
|
|
) |
|
614
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 280 |
|
615
|
|
|
|
|
|
|
&& $colset2->{hue} < 360 |
|
616
|
|
|
|
|
|
|
&& (($colset1->{hue} >= 340 |
|
617
|
|
|
|
|
|
|
&& $colset1->{hue} < 360) |
|
618
|
|
|
|
|
|
|
|| ($colset1->{hue} >= 0 |
|
619
|
|
|
|
|
|
|
&& $colset1->{hue} < 50)) |
|
620
|
|
|
|
|
|
|
) |
|
621
|
|
|
|
|
|
|
) |
|
622
|
|
|
|
|
|
|
{ |
|
623
|
|
|
|
|
|
|
# violet doesn't go with pink/red |
|
624
|
0
|
|
|
|
|
|
return 1; |
|
625
|
|
|
|
|
|
|
} |
|
626
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} > 10 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
627
|
|
|
|
|
|
|
&& $colset1->{hue} <= 40 |
|
628
|
|
|
|
|
|
|
&& ($colset1->{shade} == 2 |
|
629
|
|
|
|
|
|
|
|| $colset1->{shade} == 3) |
|
630
|
|
|
|
|
|
|
&& $colset2->{hue} > 100 |
|
631
|
|
|
|
|
|
|
&& $colset2->{hue} <= 130) |
|
632
|
|
|
|
|
|
|
|| ($colset2->{hue} > 10 |
|
633
|
|
|
|
|
|
|
&& $colset2->{hue} <= 40 |
|
634
|
|
|
|
|
|
|
&& ($colset2->{shade} == 2 |
|
635
|
|
|
|
|
|
|
|| $colset2->{shade} == 3) |
|
636
|
|
|
|
|
|
|
&& $colset1->{hue} > 100 |
|
637
|
|
|
|
|
|
|
&& $colset1->{hue} <= 130)) |
|
638
|
|
|
|
|
|
|
{ |
|
639
|
|
|
|
|
|
|
# orange doesn't go with green |
|
640
|
0
|
|
|
|
|
|
return 1; |
|
641
|
|
|
|
|
|
|
} |
|
642
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 260 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
643
|
|
|
|
|
|
|
&& $colset1->{hue} < 280 |
|
644
|
|
|
|
|
|
|
&& (($colset2->{hue} >= 350 |
|
645
|
|
|
|
|
|
|
&& $colset2->{hue} < 360) |
|
646
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 0 |
|
647
|
|
|
|
|
|
|
&& $colset2->{hue} <= 10))) |
|
648
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 260 |
|
649
|
|
|
|
|
|
|
&& $colset2->{hue} < 280 |
|
650
|
|
|
|
|
|
|
&& (($colset1->{hue} >= 350 |
|
651
|
|
|
|
|
|
|
&& $colset1->{hue} < 360) |
|
652
|
|
|
|
|
|
|
|| ($colset1->{hue} >= 0 |
|
653
|
|
|
|
|
|
|
&& $colset1->{hue} <= 10)))) |
|
654
|
|
|
|
|
|
|
{ |
|
655
|
|
|
|
|
|
|
# purple doesn't go with tomato-red or rose |
|
656
|
0
|
|
|
|
|
|
return 1; |
|
657
|
|
|
|
|
|
|
} |
|
658
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 280 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
659
|
|
|
|
|
|
|
&& $colset1->{hue} < 350 |
|
660
|
|
|
|
|
|
|
&& $colset2->{hue} >= 10 |
|
661
|
|
|
|
|
|
|
&& $colset2->{hue} < 80) |
|
662
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 280 |
|
663
|
|
|
|
|
|
|
&& $colset2->{hue} < 350 |
|
664
|
|
|
|
|
|
|
&& $colset1->{hue} >= 10 |
|
665
|
|
|
|
|
|
|
&& $colset1->{hue} < 80)) |
|
666
|
|
|
|
|
|
|
{ |
|
667
|
|
|
|
|
|
|
# purple & pink don't go with orange, yellow or green |
|
668
|
0
|
|
|
|
|
|
return 1; |
|
669
|
|
|
|
|
|
|
} |
|
670
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} > 10 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
671
|
|
|
|
|
|
|
&& $colset1->{hue} < 90 |
|
672
|
|
|
|
|
|
|
&& $colset1->{shade} != 1 |
|
673
|
|
|
|
|
|
|
&& $colset2->{hue} > 130 |
|
674
|
|
|
|
|
|
|
&& $colset2->{hue} < 210 |
|
675
|
|
|
|
|
|
|
&& $colset2->{shade} != 1) |
|
676
|
|
|
|
|
|
|
|| ($colset2->{hue} > 10 |
|
677
|
|
|
|
|
|
|
&& $colset2->{hue} < 90 |
|
678
|
|
|
|
|
|
|
&& $colset2->{shade} != 1 |
|
679
|
|
|
|
|
|
|
&& $colset1->{hue} > 130 |
|
680
|
|
|
|
|
|
|
&& $colset1->{hue} < 210 |
|
681
|
|
|
|
|
|
|
&& $colset1->{shade} != 1)) |
|
682
|
|
|
|
|
|
|
{ |
|
683
|
|
|
|
|
|
|
# orange & yellow don't go with green or cyan |
|
684
|
0
|
|
|
|
|
|
return 1; |
|
685
|
|
|
|
|
|
|
} |
|
686
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} > 50 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
687
|
|
|
|
|
|
|
&& $colset1->{hue} < 70 |
|
688
|
|
|
|
|
|
|
&& $colset1->{shade} == 1 |
|
689
|
|
|
|
|
|
|
&& $colset2->{hue} > 130 |
|
690
|
|
|
|
|
|
|
&& $colset2->{hue} < 210 |
|
691
|
|
|
|
|
|
|
&& $colset2->{shade} != 1) |
|
692
|
|
|
|
|
|
|
|| ($colset2->{hue} > 50 |
|
693
|
|
|
|
|
|
|
&& $colset2->{hue} < 70 |
|
694
|
|
|
|
|
|
|
&& $colset2->{shade} == 1 |
|
695
|
|
|
|
|
|
|
&& $colset1->{hue} > 130 |
|
696
|
|
|
|
|
|
|
&& $colset1->{hue} < 210 |
|
697
|
|
|
|
|
|
|
&& $colset1->{shade} != 1)) |
|
698
|
|
|
|
|
|
|
{ |
|
699
|
|
|
|
|
|
|
# Khaki doesn't go with green or cyan |
|
700
|
0
|
|
|
|
|
|
return 1; |
|
701
|
|
|
|
|
|
|
} |
|
702
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} > 150 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
703
|
|
|
|
|
|
|
&& $colset1->{hue} < 200 |
|
704
|
|
|
|
|
|
|
&& $colset2->{hue} > 270 |
|
705
|
|
|
|
|
|
|
&& $colset2->{hue} < 320) |
|
706
|
|
|
|
|
|
|
|| ($colset2->{hue} > 150 |
|
707
|
|
|
|
|
|
|
&& $colset2->{hue} < 200 |
|
708
|
|
|
|
|
|
|
&& $colset1->{hue} > 270 |
|
709
|
|
|
|
|
|
|
&& $colset1->{hue} < 320)) |
|
710
|
|
|
|
|
|
|
{ |
|
711
|
|
|
|
|
|
|
# turquoise/cyan doesn't go with orchid |
|
712
|
0
|
|
|
|
|
|
return 1; |
|
713
|
|
|
|
|
|
|
} |
|
714
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} > 240 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
715
|
|
|
|
|
|
|
&& $colset1->{hue} < 290 |
|
716
|
|
|
|
|
|
|
&& $colset2->{hue} > 0 |
|
717
|
|
|
|
|
|
|
&& $colset2->{hue} < 50) |
|
718
|
|
|
|
|
|
|
|| ($colset2->{hue} > 240 |
|
719
|
|
|
|
|
|
|
&& $colset2->{hue} < 290 |
|
720
|
|
|
|
|
|
|
&& $colset1->{hue} > 0 |
|
721
|
|
|
|
|
|
|
&& $colset1->{hue} < 50)) |
|
722
|
|
|
|
|
|
|
{ |
|
723
|
|
|
|
|
|
|
# blue/purple doesn't go with orange |
|
724
|
0
|
|
|
|
|
|
return 1; |
|
725
|
|
|
|
|
|
|
} |
|
726
|
0
|
0
|
0
|
|
|
|
if ($colset1->{hue} >= 290 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
727
|
|
|
|
|
|
|
&& $colset1->{hue} < 350 |
|
728
|
|
|
|
|
|
|
&& $colset2->{hue} >= 50 |
|
729
|
|
|
|
|
|
|
&& $colset2->{hue} < 110) |
|
730
|
|
|
|
|
|
|
{ |
|
731
|
|
|
|
|
|
|
# violet/pink doesn't go with yellow/green |
|
732
|
0
|
|
|
|
|
|
return 1; |
|
733
|
|
|
|
|
|
|
} |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
# glary colour don't do well with dull or pale |
|
736
|
|
|
|
|
|
|
# unless they're the same hue |
|
737
|
0
|
0
|
0
|
|
|
|
if ((($colset1->{shade} == 3 |
|
|
|
|
0
|
|
|
|
|
|
738
|
|
|
|
|
|
|
&& ($colset1->{hue} < 200 |
|
739
|
|
|
|
|
|
|
|| $colset1->{hue} > 280) |
|
740
|
|
|
|
|
|
|
&& ($colset2->{shade} == 2 |
|
741
|
|
|
|
|
|
|
|| $colset2->{shade} == 4)) |
|
742
|
|
|
|
|
|
|
|| ($colset2->{shade} == 3 |
|
743
|
|
|
|
|
|
|
&& ($colset2->{hue} < 200 |
|
744
|
|
|
|
|
|
|
|| $colset2->{hue} > 280) |
|
745
|
|
|
|
|
|
|
&& ($colset1->{shade} == 2 |
|
746
|
|
|
|
|
|
|
|| $colset1->{shade} == 4))) |
|
747
|
|
|
|
|
|
|
&& $colset1->{hue} != $colset2->{hue}) |
|
748
|
|
|
|
|
|
|
{ |
|
749
|
0
|
|
|
|
|
|
return 1; |
|
750
|
|
|
|
|
|
|
} |
|
751
|
|
|
|
|
|
|
# pink doesn't go with green or yellow, even though red does |
|
752
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 0 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
753
|
|
|
|
|
|
|
&& $colset1->{hue} < 30 |
|
754
|
|
|
|
|
|
|
&& $colset1->{shade} == 4 |
|
755
|
|
|
|
|
|
|
&& $colset2->{hue} > 60 |
|
756
|
|
|
|
|
|
|
&& $colset2->{hue} <= 120 |
|
757
|
|
|
|
|
|
|
&& $colset2->{shade} != 4) |
|
758
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 0 |
|
759
|
|
|
|
|
|
|
&& $colset2->{hue} < 30 |
|
760
|
|
|
|
|
|
|
&& $colset2->{shade} == 4 |
|
761
|
|
|
|
|
|
|
&& $colset1->{hue} > 60 |
|
762
|
|
|
|
|
|
|
&& $colset1->{hue} <= 120 |
|
763
|
|
|
|
|
|
|
&& $colset1->{shade} != 4)) |
|
764
|
|
|
|
|
|
|
{ |
|
765
|
0
|
|
|
|
|
|
return 1; |
|
766
|
|
|
|
|
|
|
} |
|
767
|
|
|
|
|
|
|
# pale orange doesn't go with green |
|
768
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 30 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
769
|
|
|
|
|
|
|
&& $colset1->{hue} < 50 |
|
770
|
|
|
|
|
|
|
&& $colset1->{shade} == 4 |
|
771
|
|
|
|
|
|
|
&& $colset2->{hue} > 90 |
|
772
|
|
|
|
|
|
|
&& $colset2->{hue} <= 130 |
|
773
|
|
|
|
|
|
|
&& $colset2->{shade} != 4) |
|
774
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 30 |
|
775
|
|
|
|
|
|
|
&& $colset2->{hue} < 50 |
|
776
|
|
|
|
|
|
|
&& $colset2->{shade} == 4 |
|
777
|
|
|
|
|
|
|
&& $colset1->{hue} > 90 |
|
778
|
|
|
|
|
|
|
&& $colset1->{hue} <= 130 |
|
779
|
|
|
|
|
|
|
&& $colset1->{shade} != 4)) |
|
780
|
|
|
|
|
|
|
{ |
|
781
|
0
|
|
|
|
|
|
return 1; |
|
782
|
|
|
|
|
|
|
} |
|
783
|
|
|
|
|
|
|
# glary red don't like khaki |
|
784
|
0
|
0
|
0
|
|
|
|
if (($colset1->{hue} >= 0 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
785
|
|
|
|
|
|
|
&& $colset1->{hue} < 30 |
|
786
|
|
|
|
|
|
|
&& $colset1->{shade} == 3 |
|
787
|
|
|
|
|
|
|
&& $colset2->{hue} > 50 |
|
788
|
|
|
|
|
|
|
&& $colset2->{hue} < 70 |
|
789
|
|
|
|
|
|
|
&& $colset2->{shade} != 3) |
|
790
|
|
|
|
|
|
|
|| ($colset2->{hue} >= 0 |
|
791
|
|
|
|
|
|
|
&& $colset2->{hue} < 30 |
|
792
|
|
|
|
|
|
|
&& $colset2->{shade} == 3 |
|
793
|
|
|
|
|
|
|
&& $colset1->{hue} > 50 |
|
794
|
|
|
|
|
|
|
&& $colset1->{hue} < 70 |
|
795
|
|
|
|
|
|
|
&& $colset1->{shade} != 3)) |
|
796
|
|
|
|
|
|
|
{ |
|
797
|
0
|
|
|
|
|
|
return 1; |
|
798
|
|
|
|
|
|
|
} |
|
799
|
|
|
|
|
|
|
|
|
800
|
0
|
|
|
|
|
|
return 0; |
|
801
|
|
|
|
|
|
|
} # is_ugly |
|
802
|
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
=head1 REQUIRES |
|
804
|
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
Graphics::ColorObject |
|
806
|
|
|
|
|
|
|
Getopt::Long |
|
807
|
|
|
|
|
|
|
Getopt::ArgvFile |
|
808
|
|
|
|
|
|
|
Pod::Usage |
|
809
|
|
|
|
|
|
|
Test::More |
|
810
|
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
812
|
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
To install this module, run the following commands: |
|
814
|
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
perl Build.PL |
|
816
|
|
|
|
|
|
|
./Build |
|
817
|
|
|
|
|
|
|
./Build test |
|
818
|
|
|
|
|
|
|
./Build install |
|
819
|
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
Or, if you're on a platform (like DOS or Windows) that doesn't like the |
|
821
|
|
|
|
|
|
|
"./" notation, you can do this: |
|
822
|
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
perl Build.PL |
|
824
|
|
|
|
|
|
|
perl Build |
|
825
|
|
|
|
|
|
|
perl Build test |
|
826
|
|
|
|
|
|
|
perl Build install |
|
827
|
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
In order to install somewhere other than the default, such as |
|
829
|
|
|
|
|
|
|
in a directory under your home directory, like "/home/fred/perl" |
|
830
|
|
|
|
|
|
|
go |
|
831
|
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
perl Build.PL --install_base /home/fred/perl |
|
833
|
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
as the first step instead. |
|
835
|
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
This will install the files underneath /home/fred/perl. |
|
837
|
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
You will then need to make sure that you alter the PERL5LIB variable to |
|
839
|
|
|
|
|
|
|
find the modules, and the PATH variable to find the script. |
|
840
|
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
Therefore you will need to change: |
|
842
|
|
|
|
|
|
|
your path, to include /home/fred/perl/script (where the script will be) |
|
843
|
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
PATH=/home/fred/perl/script:${PATH} |
|
845
|
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
the PERL5LIB variable to add /home/fred/perl/lib |
|
847
|
|
|
|
|
|
|
|
|
848
|
|
|
|
|
|
|
PERL5LIB=/home/fred/perl/lib:${PERL5LIB} |
|
849
|
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
851
|
|
|
|
|
|
|
|
|
852
|
|
|
|
|
|
|
perl(1). |
|
853
|
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
=head1 BUGS |
|
855
|
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
Please report any bugs or feature requests to the author. |
|
857
|
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
=head1 AUTHOR |
|
859
|
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
Kathryn Andersen (RUBYKAT) |
|
861
|
|
|
|
|
|
|
perlkat AT katspace dot com |
|
862
|
|
|
|
|
|
|
http://www.katspace.com |
|
863
|
|
|
|
|
|
|
|
|
864
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
|
865
|
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
Copyright (c) 2005 by Kathryn Andersen |
|
867
|
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
869
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
870
|
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
=cut |
|
873
|
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
1; # End of Graphics::Colourset |
|
875
|
|
|
|
|
|
|
__END__ |